我需要使用googleapi在gcloud存储中创建和共享一个bucket。但我在与邮递员(休息客户)联系时出错了。
我正在试用
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创建了一个访问tocken之后。并添加到标题
Authorization = ya29.VALUE_REDACTED
但是我得到错误
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
我错过了什么?
使用谷歌api浏览器,我可以成功调用api的
POST https://www.googleapis.com/storage/v1/b?project=testproject&key={YOUR_API_KEY}
{
"name": "testmanafcjbucketyy"
}
授权需要以以下格式传递。
Authorization: Bearer [oauth2_token]
如果使用Postman,"Header"字段将变为Authorization,"Value"字段将变成Bearer[WHITESPACE][oauth2_token]