简体   繁体   English

PHP 的谷歌云存储问题

[英]Google Cloud Storage issue with PHP

I am using this library: google/cloud-storage .我正在使用这个库: google/cloud-storage

In my storage I made a bucket, called: mycustombucket .在我的存储中,我制作了一个存储桶,名为: mycustombucket My goal is to upload a csv file in that bucket.我的目标是在该存储桶中上传 csv 文件。 Here is my code:这是我的代码:

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

Unfortunately, I got this error message: json key is missing the type field .不幸的是,我收到此错误消息: json key is missing the type field I found this similar POST , but it doesn't work for me.我发现了这个类似的POST ,但它对我不起作用。 I think it is also outdated.我认为它也已经过时了。

The content of the JSON, I downloaded it from here: JSON的内容,我从这里下载的: 在此处输入图像描述

Would you please suggest me and idea, how to fix this?你能建议我和想法,如何解决这个问题?

Thank you!谢谢!

In the end, I managed to get this work, by generating a key from the service account .最后,通过从service account生成密钥,我设法完成了这项工作。 From:从: 在此处输入图像描述

Please not that once you generated you will automatically download it.请注意,一旦生成,您将自动下载它。 A download button will not be available anymore.下载按钮将不再可用。 So make sure you have the key after generated it.因此,请确保您在生成密钥后拥有密钥。 I would expect to have a download button for the service account , like I have for OAuth 2.0 Client IDs (see my post).我希望service account有一个下载按钮,就像我有OAuth 2.0 Client IDs一样(请参阅我的帖子)。 But I don't:(. Finally my code:但我没有:(。最后我的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM