Google api Google Pubsub API-401错误(请求没有有效的身份验证凭据)

Google api Google Pubsub API-401错误(请求没有有效的身份验证凭据),google-api,google-cloud-pubsub,Google Api,Google Cloud Pubsub,我正试图用API_键连接到Google Pubsub API,我得到401错误-未经授权 我使用的命令是 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}" RE

我正试图用API_键连接到Google Pubsub API,我得到401错误-未经授权

我使用的命令是

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"
 }
}
如果我使用OAuth令牌执行相同的请求,它将成功

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}"
}
curl-i-H“Accept:application/json“-H”内容类型:application/json“-H”内容长度:0“-H”授权:承载“-X PUT”https://pubsub.googleapis.com/v1/projects/{project}/topics/{topicName}”
回应
200行
{
“名称”:“项目/{project}/topics/{topicName}”
}

为什么请求不使用API密钥

所有云发布/订阅API调用都需要身份验证。API密钥仅用于在请求上附加项目信息,而不提供任何身份验证。这就是为什么添加API密钥是不够的