0

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

对于 GTask

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。任何提示这里有什么问题?

4

2 回答 2

0

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

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

于 2020-01-06T20:54:40.313 回答
0

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

于 2020-02-13T07:46:05.620 回答