我有一个具有域范围委派的服务帐户,并且它对于Calendar 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('[email protected]')
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('[email protected]')
service = build('calendar', 'v3', credentials=delegated_credentials)
events = service.events().list(calendarId=SUBJECT,timeMin=now,maxResults=10,orderBy='startTime',singleEvents=True).execute()
我正在使用此lib https://github.com/googleapis/google-api-python-client。任何提示这里有什么问题吗?
并非所有API都支持域范围的委派。如果他们这样做,您将在Auth文档中看到它。
Calendar API支持整个域的委托,而Tasks API不支持。