【问题标题】:GTasks API Service Account: Client is unauthorized to retrieve access tokens using this methodGTasks API 服务帐户:客户端未经授权使用此方法检索访问令牌
【发布时间】:2020-01-06 14:54:32
【问题描述】:

我有一个具有域范围委派的服务帐户,它在日历 API 上运行良好。我可以在没有同意屏幕的情况下冒充组织内的其他用户参加 Google 日历中的 CRUD 事件。现在我正在尝试使用 GTasks API 但出现错误。

对于 GTasks

credentials = service_account.Credentials.from_service_account_file('service-account.json', scopes=['https://www.googleapis.com/auth/tasks'])
delegated_credentials = credentials.with_subject('username@company.com')
service = build('tasks', 'v1', credentials=delegated_credentials)
tasklists = service.tasklists().list(maxResults=10).execute()

并得到以下错误。

('unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.', '{\n  "error": "unauthorized_client",\n  "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."\n}')

对于 GCalendar,工作正常

credentials = service_account.Credentials.from_service_account_file('service-account.json', scopes=['https://www.googleapis.com/auth/calendar'])
delegated_credentials = credentials.with_subject('username@company.com')
service = build('calendar', 'v3', credentials=delegated_credentials)
events = service.events().list(calendarId=SUBJECT,timeMin=now,maxResults=10,orderBy='startTime',singleEvents=True).execute()

我正在使用这个库https://github.com/googleapis/google-api-python-client。任何提示这里有什么问题?

【问题讨论】:

  • 您是否检查过您的项目中是否启用了Tasks API?如果启用了 api,请检查 console.developers.google.com;如果您域中的用户启用了 Tasks,请检查 admin.google.com。

标签: python google-api google-api-python-client google-tasks-api google-tasks


【解决方案1】:

并非所有 API 都支持域范围的委派。如果他们这样做,您将在 Auth 文档中看到它。

日历 API 支持域范围的委派,而任务 API 不支持。

【讨论】:

    【解决方案2】:

    Google 日历和任务都支持域范围的委派,我正在使用它。我的建议是:

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 2019-08-14
      • 1970-01-01
      • 2019-01-27
      • 2018-12-01
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多