我试图通过python调用google calendar 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)
答案 0 :(得分:3)
您可能必须以.json文件的形式删除现有凭据。我有类似的“权限不足”问题,我不得不删除存储的凭据。我还有另一个问题,就是因为在他们的教程中尝试了一些谷歌的脚本,我不知不觉地将凭据存储在我的主目录(users / home)中隐藏的.credentials文件夹中。由于它们是隐藏的,我不得不通过终端(在Mac上)查找它们,并在那里删除它们。删除后,问题就解决了,因为我可以创建适合我新脚本范围的新的正确凭据。
答案 1 :(得分:0)
您的身份验证有问题。权限不足意味着您无权访问。
我可以验证范围https://www.googleapis.com/auth/calendar
是否足以在primary
日历上显示ACL.list。
答案 2 :(得分:0)
您必须找到“calendar-dotnet-quickstart.json”文件的位置并将其删除。我使用.NET示例,我必须调试以下代码找到确切的位置。
string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath,“。credentials / calendar-dotnet-quickstart.json”);
然后将范围更改为以下方式并重建解决方案。
string [] scopes = {CalendarService.Scope.Calendar};
您会注意到谷歌会要求再次确认访问权限。