【发布时间】:2021-05-16 14:20:07
【问题描述】:
我正在尝试使用 curl 从我的家用计算机运行 Compute Engine API(不要使用 gconsole 或 sdks)。 我可以使用 OAuth 2.0 访问获得响应,但不能仅使用 api-key 获得响应。 我可以只使用 API 密钥来使用 API 吗?
- 成功
请求
curl https://compute.googleapis.com/compute/v1/projects/{PROJECT_ID}/zones/{ZONE}/instances/{INSTANCE_ID} 'Authorization: Bearer [ACCESS_TOKEN]'
- 失败
请求
curl https://compute.googleapis.com/compute/v1/projects/{PROJECT_ID}/zones/{ZONE}/instances/{INSTANCE_ID}?key={MY_API_KEY}
回复
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
【问题讨论】:
-
Google Compute Engine API 不支持 API 密钥进行授权。
标签: curl google-cloud-platform google-compute-engine