Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决Symfony中Google存储客户端的错误?_Php_Symfony_Google Cloud Storage_Flysystem Google Drive - Fatal编程技术网

Php 如何解决Symfony中Google存储客户端的错误?

Php 如何解决Symfony中Google存储客户端的错误?,php,symfony,google-cloud-storage,flysystem-google-drive,Php,Symfony,Google Cloud Storage,Flysystem Google Drive,我正在Symforny 5中开发一个项目,我想使用Google云存储,安装带有superbalist/flysystem Google存储支持的HPLeague/flysystem捆绑包,如文档所示,在Google控制台和bucket中生成credentials.json,但我遇到以下错误: { "error": { "code": 401, "message": "Invalid Credentials", "errors": [ { "message": "Invalid Cr

我正在Symforny 5中开发一个项目,我想使用Google云存储,安装带有superbalist/flysystem Google存储支持的HPLeague/flysystem捆绑包,如文档所示,在Google控制台和bucket中生成credentials.json,但我遇到以下错误:

{
 "error": {
 "code": 401,
 "message": "Invalid Credentials",
 "errors": [
 {
  "message": "Invalid Credentials",
  "domain": "global",
  "reason": "authError",
  "locationType": "header",
  "location": "Authorization"
 }
 ]
}
}
\vendor\google\cloud-core\src\RequestWrapper.php (line 362)
配置:

flysystem:
storages:
    default.storage:
        adapter: 'local'
        options:
            directory: '%kernel.project_dir%/var/storage/default'

    gcs.storage:
        adapter: 'gcloud'
        options:
            client: 'gcloud_client_service' # The service ID of the Google\Cloud\Storage\StorageClient instance
            bucket: 'test-storage'
            #prefix: 'optional/path/prefix'
            api_url: 'https://storage.googleapis.com'
在职

gcloud_client_service:
    class: Google\Cloud\Storage\StorageClient
    arguments:
        - projectId: 'storage-project'
        - keyFilePath: '../credentials.json'

由于凭据设置不正确,因此出现错误。如果要使用JSON文件,解决此问题的一种方法是在代码中使用以下内容设置凭据:

putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
另一方面,在本文档中,您可以找到另一种方法来设置与地面军事系统的连接配置。另外,请记住添加要使用的服务帐户,转到并将“存储桶管理员”角色添加到该SA


这两个选项都应该对你有用。

有点晚了,但可能对其他人有帮助。今天我在Symfony 5.1上遇到了同样的问题,通过设置services.yaml解决了这个问题:

services:    
      gcloud_client_service:
        class: Google\Cloud\Storage\StorageClient
        arguments:
          $config:
            keyFilePath: '%kernel.project_dir%/config/my_testing_config.json'
            projectId: 'my-testing-project'