I am trying to connect to the Google Pubsub API with the API_KEY and I get 401 Error - Unauthorised.
The command I am using is
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -H "Content-Length: 0" -X PUT "https://pubsub.googleapis.com/v1/projects/{project}/topics/{topicName}?key={api-key}"
RESPONSE
{
"error": {
"code": 401,
"message": "The request does not have valid authentication credentials.",
"status": "UNAUTHENTICATED"
}
}
If I do the same request using OAuth token, it succeeds
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -H "Content-Length: 0"-H "Authorization: Bearer <access_token>" -X PUT "https://pubsub.googleapis.com/v1/projects/{project}/topics/{topicName}"
RESPONSE
200 OK
{
"name": "projects/{project}/topics/{topicName}"
}
Why is the request not working with the API key
答案 0 :(得分:3)
所有Cloud Pub / Sub API调用都需要身份验证。 API密钥仅用于在请求上附加项目信息,而不提供任何身份验证。这就是为什么它不足以添加API密钥。