【发布时间】:2014-09-01 11:36:27
【问题描述】:
我正在尝试下载我的用户可以看到的 Google 日历列表。我已经设置了一个服务帐户,并且我有这个代码(它适用于 Analytics API 的不同帐户):
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
import pprint
def prepare_credentials():
f = file(keyFilePath, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_account_email_address, key,
scope='https://www.googleapis.com/auth/calendar.readonly')
return credentials
http = httplib2.Http()
credentials = prepare_credentials()
http = credentials.authorize(http)
service = build('calendar', 'v3', http=http)
httpRequest = service.calendarList().list()
data = httpRequest.execute()
pprint.pprint(data)
结果:
{u'etag': u'"YXs7dfDSFSFD9F0k/sofIhuT4dSLyxKaRH7vNpx5BOEU"',
u'items': [],
u'kind': u'calendar#calendarList',
u'nextSyncToken': u'00001405024697194000'}
问题是,我知道我可以访问日历,而且我什至使用过“试试看!”本页部分:https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list,返回预期结果,约10个日历。我尝试了不同版本的范围参数('https://www.googleapis.com/auth/calendar.readonly',和 ['https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/calendar.readonly']),我还尝试将我自己的电子邮件地址添加为“prn”和“子”参数,所有这些都给我“拒绝访问”错误。我不知道为什么我可以使用我的服务帐户获得授权,但是当这些结果可以通过不同的身份验证方法清楚地查看时,我无法实际查看结果。
我做错了什么?
【问题讨论】:
标签: google-calendar-api google-api-python-client