通过服务 ac 访问同一 Python 程序中的多个 Google Cloud API 服务会出现 Unauthorized_client 错误
我创建了一个服务帐户,并为 DwD 提供了必要的范围。
https://www.googleapis.com/auth/admin.directory.user.readonly
https://www.googleapis.com/auth/admin.directory.group.readonly
https://www.googleapis.com/auth/cloud-platform.read-only
https://www.googleapis.com/auth/cloudplatformprojects.read-only
https://www.googleapis.com/auth/iam
https://www.googleapis.com/auth/apps.groups.settings
我正在尝试在同一个Python程序中访问CloudResourceManager API、IAM API和Admin SDK API(通过管理员模拟)的Google API服务。当我使用管理服务时,出现 Unauthorized_Client 错误。
('unauthorized_client: Client is unauthorized to retrieve access tokens using this
method.', u'{"error" : "unauthorized_client", "error_description" : "Client is
unauthorized to retrieve access tokens using this method."}')
但是,如果我只使用 Admin API 而不使用其他 API,它的工作方式会很奇怪。这与范围重叠有关吗? 提前致谢。
@DalmTo 尝试过这两种方式进行身份验证 1)
from google.oauth2 import service_account
credentials = Service_account.Credentials.from_service_account_file("keys.json", scopes=scopes)
from oauth2client.service_account import ServiceAccountCredentials
credentials = ServiceAccountCredentials.from_json_keyfile_name("Keys.json", scopes=scopes)
I have a service account created and given DwD with necessary scopes.
https://www.googleapis.com/auth/admin.directory.user.readonly
https://www.googleapis.com/auth/admin.directory.group.readonly
https://www.googleapis.com/auth/cloud-platform.read-only
https://www.googleapis.com/auth/cloudplatformprojects.read-only
https://www.googleapis.com/auth/iam
https://www.googleapis.com/auth/apps.groups.settings
I am trying to access Google API services of CloudResourceManager API , IAM API and Admin SDK API(through admin impersonation), in the same Python program. I am getting an Unauthorized_Client error when I use Admin service.
('unauthorized_client: Client is unauthorized to retrieve access tokens using this
method.', u'{"error" : "unauthorized_client", "error_description" : "Client is
unauthorized to retrieve access tokens using this method."}')
However, If I use only Admin API without other APIs, it works strangely. Is it something to do with the scopes overlap?
Thanks in Advance.
@DalmTo Tried in these two ways for authentication
1)
from google.oauth2 import service_account
credentials = Service_account.Credentials.from_service_account_file("keys.json", scopes=scopes)
from oauth2client.service_account import ServiceAccountCredentials
credentials = ServiceAccountCredentials.from_json_keyfile_name("Keys.json", scopes=scopes)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论