首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP的Google云存储问题

PHP的Google云存储问题
EN

Stack Overflow用户
提问于 2021-01-22 23:39:08
回答 1查看 47关注 0票数 0

我正在使用这个库:google/cloud-storage

在我的存储中,我创建了一个存储桶,名为:mycustombucket。我的目标是上传该存储桶中的csv文件。下面是我的代码:

代码语言:javascript
复制
  $storage = new StorageClient([
     'projectId' => 'my project id',
     'keyFile' => json_decode('{
       "web":{
          "client_id":"my client id",
          "project_id":"my project id",
          "auth_uri":"https://accounts.google.com/o/oauth2/auth",
          "token_uri":"https://oauth2.googleapis.com/token",
          "auth_provider_x509_cert_url":"my auth value",
          "client_secret":"my client secret"
       }
      }', true)
  ]);
  $bucket = $storage->bucket('mycustombucket');
  $bucket->upload(
           fopen('path/to/my/file.csv', 'r')
  );

不幸的是,我收到了这个错误消息:json key is missing the type field。我找到了这个类似的POST,但它不适用于我。我认为这也是过时的。

JSON的内容,我从这里下载的:

你能建议我和想法,如何解决这个问题吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-23 00:14:15

最后,通过从service account生成密钥,我成功地完成了这项工作。发自:

请不要说,一旦你生成,你会自动下载它。下载按钮将不再可用。因此,在生成密钥后,请确保您拥有它。我希望有一个service account的下载按钮,就像我在OAuth 2.0 Client IDs上的下载按钮(见我的帖子)。但我没有:(。最后是我的代码:

代码语言:javascript
复制
    $storage = new StorageClient([
        'projectId' => 'projectId' => 'my project id',
        'keyFile' => json_decode('{
              "type": "service_account",
              "project_id": "my project id",
              "private_key_id": "my key id",
              "private_key": "my key",
              "client_email": "email@email.com",
              "client_id": "client id",
              "auth_uri": "https://accounts.google.com/o/oauth2/auth",
              "token_uri": "https://oauth2.googleapis.com/token",
              "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
              "client_x509_cert_url": "url here"
        }', true)
    ]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65848175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档