【发布时间】:2015-05-17 23:45:52
【问题描述】:
我在尝试通过 python 调用谷歌日历 API 的 acl.list 方法时收到Insufficient permissions。
service.acl().list(calendarId='primary').execute();
*** HttpError: <HttpError 403 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/acl?alt=json returned "Insufficient Permission">
我正在使用文档中推荐的范围“https://www.googleapis.com/auth/calendar”。此外,其他 API 方法也可以工作,例如 service.calendarList
service.calendarList().list(pageToken=page_token).execute()
我错过了什么?
我使用的代码几乎完全基于他们提供的示例:
import sys
from oauth2client import client
from googleapiclient import sample_tools
def main(argv):
# Authenticate and construct service.
# import pdb;pdb.set_trace()
service, flags = sample_tools.init(
argv, 'calendar', 'v3', __doc__, __file__,
# scope='https://www.googleapis.com/auth/calendar.readonly')
scope='https://www.googleapis.com/auth/calendar')
try:
page_token = None
while True:
calendar_list = service.calendarList().list(pageToken=page_token).execute()
for calendar_list_entry in calendar_list['items']:
print calendar_list_entry['summary']
page_token = calendar_list.get('nextPageToken')
service.acl().list(calendarId='primary').execute();
if not page_token:
break
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run'
'the application to re-authorize.')
if __name__ == '__main__':
main(sys.argv)
【问题讨论】:
-
您使用哪种身份验证?您是否使用广泛的委托身份验证?如果是,您需要验证您是否已授权您的子账号访问API。
-
@erjoalgo 关于只读访问为何失败的任何想法?我找不到在任何地方记录此内容所必需的读/写权限,但没有它们就无法工作。我只想查看/list() 访问控制列表——而不是修改它。
标签: google-api google-calendar-api google-api-python-client