poa*_*oas 5 php google-cloud-storage google-cloud-platform
我正在尝试检查 Laravel PHP 中是否存在存储桶。我在 contains() 方法上收到 403 错误。为什么?
请参阅第 160 行https://github.com/googleapis/google-cloud-php/blob/master/Storage/src/Bucket.php
$storageClient = new \Google\Cloud\Storage\StorageClient([
'projectId' => env('GCS_PROJECT_ID'),
'keyFilePath' => storage_path(env('GCS_KEY_FILE')),
]);
$bucket = $storageClient->bucket('mybucketname');
if (!$bucket->exists()) {
$bucket = $storageClient->createBucket('mybucketname');
}
{ "error": {
"code": 403,
"message": "myaccount@api-project-xxxxxxxxx.iam.gserviceaccount.com does not have storage.buckets.get access to downloads.",
"errors": [ {
"message": "myaccount@api-project-xxxxxxxx.iam.gserviceaccount.com does not have storage.buckets.get access to mybucketname.",
"domain": "global",
"reason": "forbidden"
} ]
} }
Run Code Online (Sandbox Code Playgroud)
您的服务帐户没有权限storage.buckets.get。为了检查存储桶是否存在并创建它,请分配roles/storage.admin给您的服务帐户。
作为参考,请参阅: