【问题标题】:"Insufficient permissions" on google calendar api's acl.list谷歌日历 api 的 acl.list 上的“权限不足”
【发布时间】: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


【解决方案1】:

您可能必须以 .json 文件的形式删除现有凭据。我遇到了类似的“权限不足”问题,我不得不删除存储的凭据。我有一个额外的问题,因为在他们的教程中尝试了一些谷歌的脚本,我在不知不觉中将凭据存储在我的主目录(用户/主目录)的隐藏 .credentials 文件夹中。由于它们被隐藏了,我不得不通过终端(在 Mac 上)查找它们,并在那里删除它们。删除后,问题就解决了,因为我可以创建新的和适当的凭据,适合我的新脚本的范围。

【讨论】:

  • 感谢您指明要删除的存储凭据的位置 - 我能够转到我的 .credentials 文件夹并从那里删除文件。
  • 哇...根本不知道为什么任何事情都不起作用!这修复了它:)
【解决方案2】:

您的身份验证有问题。权限不足意味着您没有访问权限。

我可以验证https://www.googleapis.com/auth/calendar 的范围是否足以在primary 日历上显示ACL.list

【讨论】:

  • “您的身份验证有问题”。你能详细说明一下吗?
【解决方案3】:

您必须找到“calendar-dotnet-quickstart.json”文件的位置并将其删除。我使用了 .NET 示例,并且必须调试以下代码以查找确切位置。

字符串 credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

然后如下更改范围并重建解决方案。

字符串[] 范围 = { CalendarService.Scope.Calendar};

你会注意到谷歌会要求再次确认访问。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 2017-03-13
    • 2019-10-22
    • 2011-04-27
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多