首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从Google Calendar获取Google Calendar条目

从Google Calendar获取Google Calendar条目
EN

Stack Overflow用户
提问于 2018-07-22 09:31:12
回答 1查看 842关注 0票数 1

我正在尝试编写一个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日历条目,还有其他的建议吗?

EN

回答 1

Stack Overflow用户

发布于 2018-07-24 19:43:11

一个简单的解决方案是使用日历的私有ical URL(在日历设置中列出),然后解析检索到的日历文件。这不需要OAuth就可以工作。您将无法检索这些URL的列表,用户需要自己查找它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51461341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档