【问题标题】:How to discover the scope associated to my Google API credentials?如何发现与我的 Google API 凭据关联的范围?
【发布时间】:2022-07-18 23:53:46
【问题描述】:

我正在使用 Google earthengine 来运行 GIS 计算。最近谷歌添加了项目来管理创建的资产,这意味着我需要使用谷歌云 API 来找回我的项目名称。

我使用服务帐户连接到 API,但我无法访问我的项目列表。不过,我确定我已将“https://www.googleapis.com/auth/cloudplatformprojects.readonly”范围添加到我的帐户中。

有没有办法让我使用 API 检查我当前范围的列表?

import ee 

ee.Iniitialize() 

# that's the credential I would like to test 
# it's a ServiceAccountCredential like any other Google API (I use it to connect to drive as well)
cred = ee.Credentials()

# something like 
for scope in cred.scopes(): 
    print(scope)

【问题讨论】:

  • 您要连接到哪个 api,我可以获得您正在关注的文档链接吗?
  • 我正在尝试完成以下工作流程:stackoverflow.com/questions/58366396/…,但由于范围问题而被系统拒绝

标签: python google-api google-authentication


【解决方案1】:

您可以从 Google 的 OAuth 服务 tokeninfo 方法中查找访问和身份令牌:

  • https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={access_token}
  • https://www.googleapis.com/oauth2/v1/tokeninfo?id_token={id_token}

还有一个 Google CLI“OAuth 工具”oauth2l,您也觉得它很有用。

它包括(除其他外)oauth2l info 方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 2013-01-19
    • 1970-01-01
    相关资源
    最近更新 更多