微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP 的 Google Cloud Storage 问题

如何解决PHP 的 Google Cloud Storage 问题

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

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

  $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 的内容,我是从这里下载的:

enter image description here

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

谢谢!

解决方法

最后,通过从 service account 生成密钥,我设法完成了这项工作。从: enter image description here

请注意,一旦生成,您将自动下载它。下载按钮将不再可用。因此,请确保您在生成密钥后拥有密钥。我希望为 service account 提供一个下载按钮,就像我为 OAuth 2.0 Client IDs 提供的一样(请参阅我的帖子)。但我不:(。 最后我的代码:

    $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)
    ]);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。