我正在尝试编写一个python脚本,允许您从google日历中获取条目。我尝试使用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获取google日历条目,还有其他的建议吗?
发布于 2018-07-24 19:43:11
一个简单的解决方案是使用日历的私有ical URL(在日历设置中列出),然后解析检索到的日历文件。这不需要OAuth就可以工作。您将无法检索这些URL的列表,用户需要自己查找它们。
https://stackoverflow.com/questions/51461341
复制相似问题