在https://console.cloud.google.com/下,我创建了新的应用程序,创建了带有凭据的json文件,在.env中我添加了行:
GOOGLE_CLOUD_KEY_FILE="client_secret_NNNNMYFILE.apps.googleusercontent.com.json"但是当我把我的图片上传到google云时,我发现了错误:
A keyfile was given, but it does not contain a project ID. This can indicate an old and obsolete keyfile, in which case you should create a new one. To suppress this message, set `suppressKeyFileNotice` to `true` in your client configuration. To learn more about generating new keys, see this URL: https://cloud.google.com/iam/docs/creating-managing-service-account-keys#creating_service_account_keys这是什么样的项目ID?这是在console.cloud.google下的一些选择吗?我可以把它放在哪里?我打开了上面的链接,但没有发现任何提到的“suppressKeyFileNotice”.
Project/public/client_secret_278938643693-44adrhckvqgbcikr943lj29tvg89hojr.apps.googleusercontent.com.json文件有内容:
{"web":{"client_id":"NNNNNNhojr.apps.googleusercontent.com","project_id":"tads-gsc-test","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_secret":"NNNN-NNNNNNNN","redirect_uris":["https://my-site-ref.com/authorized_redirect"],"javascript_origins":["https:///my-site-ref.com"]}}管制行动:
$fileContents= Storage::url('public/todo_list_app/1/logo-file.jpeg'); ;
$disk = Storage::disk('gcs');
$disk->put('avatars/1', $fileContents);
$exists = $disk->exists('logo-file.jpeg');
$time = $disk->lastModified('file1.jpg');在config/config ystems.php中:
'gcs' => [
'driver' => 'gcs',
'key_file_path' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
'key_file' => [], // optional: Array of data that substitutes the .json file (see below)
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'), // optional: is included in key file
'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', ''), // optional: /default/path/to/apply/in/bucket
'apiEndpoint' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below
'visibility' => 'public', // optional: public|private
'metadata' => ['cacheControl'=> 'public,max-age=86400'], // optional: default metadata
],我怎么才能修好它?
提前感谢!
发布于 2022-07-05 09:48:12
使用Google构建应用程序的一般过程遵循以下一般步骤:
为您的Libraries
应根据应用程序的需要和运行位置选择应用程序凭据。
要在Google中使用服务帐户,您需要在代码运行的地方设置一个环境变量5。
通过设置环境变量GOOGLE_APPLICATION_CREDENTIALS向应用程序代码提供身份验证凭据。此变量仅适用于当前的shell会话。如果希望变量应用于未来的shell会话,请在shell启动文件中设置变量,例如在~/.bashrc或~/.profile file中。
此外,根据注释和建议,您使用的是OAuth 2.0客户端ID秘密json文件,而应该使用正确的服务帐户密钥json。
key_file_path' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
有关更多信息,请参考以下内容
1个https://cloud.google.com/iam/docs/creating-managing-service-account-keys#get-key
2:https://cloud.google.com/docs/authentication/getting-started
3 :https://cloud.google.com/docs/authentication/best-practices-applications
4:https://cloud.google.com/docs/authentication/production#automatically
https://stackoverflow.com/questions/72844040
复制相似问题