我正在尝试使用Google Cloud Storage JSON API通过http调用从存储桶中检索文件。
我从GCE中与存储存储桶相同的项目中的Container中进行冰壶操作,并且服务帐户对存储桶具有读取访问权限
以下是请求的模式:
https://storage.googleapis.com/{bucket}/{object}
根据API控制台,我不需要任何特定的东西,因为服务帐户提供应用程序默认凭据。然而,我一直有这样的想法:
Anonymous caller does not have storage.objects.get
我还试图为项目创建一个API键,并将其附加到url (https://storage.googleapis.com/{bucket}/{object}?key={key}
)中,但我仍然得到相同的401错误。
如何授权查询此接口的请求?
发布于 2018-11-05 11:59:00
您使用的URL不正确。API使用以https://www.googleapis.com/storage/v1/b
开头的URL。
不推荐使用API密钥。相反,您应该使用Bearer: token
。我将展示这两种方法。
要获取gcloud默认配置的访问令牌:
gcloud auth print-access-token
然后在您的curl
请求中使用令牌。使用gcloud命令中的令牌替换TOKEN。
要列出存储桶,请执行以下操作:
curl -s -H "Authorization: Bearer TOKEN" https://www.googleapis.com/storage/v1/b
curl https://www.googleapis.com/storage/v1/b?key=APIKEY
列出对象的步骤:
curl -s -H "Authorization: Bearer TOKEN" https://www.googleapis.com/storage/v1/b/examplebucket/o
curl https://www.googleapis.com/storage/v1/b/examplebucket/o?key=APIKEY
发布于 2018-11-06 01:22:01
如果你能够创建另一个集群,你可以像这样获得权限:点击“高级编辑”
下一步点击“允许所有云API的完全访问”
就是这样:D
https://stackoverflow.com/questions/53135841
复制相似问题