我需要使用google api在gcloud存储中创建和共享一个存储桶。但是当我遇到邮递员(休息客户)时,我收到了一个错误。
我试着用
url
-------
https://www.googleapis.com/storage/v1/b?project=testproject
request body
------------
{
"name":"testbucketmanafnew"
}
我收到了错误
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
在iam使用OAuth 2.0 Playground创建访问权限之后。并添加到标题
Authorization = ya29.VALUE_REDACTED
但我收到了错误
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
我错过了什么?
使用Google api explorer,我能够成功调用api
POST https://www.googleapis.com/storage/v1/b?project=testproject&key={YOUR_API_KEY}
{
"name": "testmanafcjbucketyy"
}
答案 0 :(得分:2)
授权需要在以下format中传递。
Authorization: Bearer [oauth2_token]
如果您使用Postman,“Header”字段将变为授权,“Value”字段将成为Bearer [WHITESPACE] [oauth2_token]