【问题标题】:401 error when trying to list Compute Engine instances using REST API and api key尝试使用 REST API 和 api 密钥列出 Compute Engine 实例时出现 401 错误
【发布时间】:2014-09-26 10:43:59
【问题描述】:

我正在尝试使用 REST API 和服务器应用程序的公共 api 密钥列出 Compute Engine 项目中的所有实例。尝试使用和不使用授权标头,但不断收到响应 401:

APIKEY="API KEY"
PROJECT="PROJECT ID"

curl https://www.googleapis.com/compute/v1/projects/$PROJECT/aggregated/instances?key=$APIKEY

curl -H "Authorization: key=$APIKEY" https://www.googleapis.com/compute/v1/projects/$PROJECT/aggregated/instances?key=$APIKEY

我在创建 api 密钥时允许任何 IP 连接。我错过了什么?

【问题讨论】:

    标签: google-compute-engine


    【解决方案1】:

    API key 只能在您使用的 API 不需要访问私人用户数据时使用。在您尝试使用的instances:list API 的 Google 文档中,您可以阅读链接“read more about authentication and authorization”,您可以在其中发现向 Google Compute Engine 发出的请求必须使用 OAuth 2.0 来授权请求​​。这就是在尝试卷曲此链接时,您会收到一条错误消息“需要 401 登录”的原因。 因此,您需要先创建OAuth 流进行身份验证。

    【讨论】:

      猜你喜欢
      • 2022-08-20
      • 1970-01-01
      • 1970-01-01
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      相关资源
      最近更新 更多