我在尝试模仿管理员从谷歌应用程序市场安装我的应用程序的域的用户时收到此错误。
Client is unauthorized to retrieve access tokens using this method.
我正在运行的代码:
credentials = service_account.ServiceAccountCredentials.from_json_keyfile_dict(key_data, scopes=REQUIRED_SCOPES) # The key data is generated when creating a service account from my project.
creds = credentials.create_delegated('user1@my_domain.com')
http_client = creds.authorize(Http())
discovery.build('gmail', 'v1', http=http_client)
答案 0 :(得分:0)
要冒充用户,您必须grant the service account access。此外,当新创建被模拟的帐户时,会发生此错误。
您可以在此处查看:Client is unauthorized to retrieve access tokens using this method Gmail API C#
服务帐户需要获得授权,或者无法访问域的电子邮件。
"客户未经授权使用此方法检索访问令牌"
表示您未经授权正确检查Delegating domain-wide authority to the service account
希望这有帮助!