通过服务 ac 访问同一 Python 程序中的多个 Google Cloud API 服务会出现 Unauthorized_client 错误

发布于 2025-01-09 18:54:38 字数 1255 浏览 1 评论 0原文

我创建了一个服务帐户,并为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文