使用 Google Cloud Platform Buckets 的凭据无效

奥尼尔

我们在 Google Cloud Platform 中有一个存储桶来管理图片。我正在尝试使用 Curl 将图片上传到它。

相对于此处链接的官方文档,这是我使用的 Curl 命令:

curl -X POST --data-binary @cat.jpeg \
    -H "Authorization: Bearer A_STRING_SUPPOSED_TO_BE_A_KEY" \
    -H "Content-Type: image/jpeg" \
    "https://storage.googleapis.com/upload/storage/v1/b/upload_zone/o?uploadType=media&name=cat"

这是我们得到的答案:

{
  "error": {
    "code": 401,
    "message": "Invalid Credentials",
    "errors": [
      {
        "message": "Invalid Credentials",
        "domain": "global",
        "reason": "authError",
        "locationType": "header",
        "location": "Authorization"
      }
    ]
  }
}

我们的密钥似乎无效,我们不确定使用什么作为授权密钥。我们在哪里可以找到使用 Google Cloud Platform Bucket 所需的 OAUTH2.0-key,我们是否需要在某处生成它?

编辑:我们已经使用 OAuth 2.0-Playground 生成了一个密钥,并且成功了!但是密钥每 3000 秒过期一次......

卡梅伦

如果您已经使用 gcloud sdk 对 Google 进行了身份验证,则可以像这样获取密钥:

-H "Authorization: Bearer $(gcloud auth print-identity-token)"

因此,使用上面的示例,这应该有效:

curl -X POST --data-binary @cat.jpeg \
-H "Authorization: Bearer $(gcloud auth print-identity-token)" \
-H "Content-Type: image/jpeg" \
"https://storage.googleapis.com/upload/storage/v1/b/upload_zone/o?uploadType=media&name=cat"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Go SDK for Google Cloud Platform获取项目ID?

在Golang中使用Google Cloud Platform中的存储桶

Google Cloud Platform:如何重命名Google Cloud Platform项目?

使用Java挂起Google Cloud Platform实例

使用Google Cloud Platform Deployment Manager模板创建存储桶

Google Cloud Platform个人帐单

在中国可以使用Google Cloud Platform吗?

尝试连接时,Google Cloud Storage给我授权码401无效的凭据

如何使用python从google-cloud-platform下载数据?

Google Cloud Datastore Emulator不使用默认凭据

Google Cloud Platform发布/订阅发布者,如何提供默认应用程序凭据以外的凭据

使用Google Cloud Platform部署React应用程序

Google Cloud Platform数据显示

Google Cloud Platform文件位置

使用Google Cloud Platform时如何锁定状态文件?

Google Cloud Platform使用InstanceGroupManager启动多个实例

Google Cloud Platform:使用api列出可用的项目

Google Cloud Platform API,用于配置OAuth2同意书和凭据

Google Cloud Platform修复SSH

Google Cloud Messaging VS Google Cloud Platform

在ExpressJS中使用Google Cloud Platform的错误报告

使用凭据保护 Google Cloud Storage 存储分区

Google Cloud Platform - 在代码中定义凭据

Google Cloud AppEngine - NPM 依赖 - 无效的身份验证凭据

Google Cloud Platform AI Notebook - 如何确保使用 GPU?

Google Cloud Platform SQL 实例将不接受使用自定义用户凭据的 **nodejs 应用程序** 连接

在哪里保存 Google Cloud Platform 服务帐户凭据

使用 Python 的 Google Cloud Platform SDK

允许外部用户使用 Google Cloud Platform 帐户