【发布时间】:2018-07-22 01:31:11
【问题描述】:
我正在尝试编写一个允许您从谷歌日历中获取条目的 python 脚本。 我尝试在此处使用 Google Calendar API 的示例:https://developers.google.com/calendar/quickstart/python
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
import datetime
# Setup the Calendar API
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
print('Getting the upcoming 10 events')
events_result = service.events().list(calendarId='primary', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
print(start, event['summary'])
当我使用命令行“python quickstart.py”运行它时,我得到一个
ModuleNotFoundError: No module named 'apiclient.discovery'
我尝试安装 google api python 客户端,但仍然无法正常工作。
pip install --upgrade google-api-python-client
conda install -c conda-forge google-api-python-client
对于如何使用 python 获取谷歌日历条目还有其他建议吗?
【问题讨论】:
-
python2 还是 python3?假设 pip 确实做了什么,它在哪里安装了文件?
标签: python google-calendar-api