【发布时间】:2020-12-14 12:39:25
【问题描述】:
我正在尝试列出我的存储项目中的所有(甚至一些)存储桶。如果我知道存储桶的名称,“存储桶”函数将获取存储桶。但是我不能使用“buckets”来列出我项目中的bucket:
$client = new StorageClient(
[
'projectId' => <my project id>,
'keyFile' => json_decode(file_get_contents(<my json file>))
]
);
$bucket_name = 'idx-mls-info-gs-ihouseprd.com';
$one_bucket = $client->bucket( $bucket_name );
print "GOT BUCKET: " . $one_bucket->name() . "\n";
// NOTE: this works
$prefix = 'idx-';
print "Getting buckets (prefix: $prefix)\n";
$buckets = $client->buckets( ['prefix' => $prefix] );
foreach ( $buckets as $bucket )
{
printf('Bucket: %s' . PHP_EOL, $bucket->name());
}
print "done with buckets"
// THIS DOES NOTHING
我的服务帐户具有“存储管理员”角色。我很困惑。 注意:我使用的是 PHP 5.6,以防万一。 Composer 安装 GCS 库没有问题,所以我认为没问题。
好的,所以我一定遗漏了一些东西。使用我的获取单个存储桶的测试用例,然后我使用了 $one_bucket->object(),并成功获取了一个对象。但是如果我尝试 $one_bucket->objects(),我又什么也得不到。因此,无论是存储桶还是对象,GCS 中实体的多种情况都对我不起作用。也许这是一个线索。
更多信息: 命中迭代器时出现异常(foreach $buckets as $bucket):
异常 'Exception' 和消息 'exception 'Google\Cloud\Core\Exception\ServiceException' 和消息 '4096:Argument 2 传递给 Google\Auth\CredentialsLoader::makeCredentials() 必须是数组类型,对象给定,在第 158 行的 /home/httpd/idxv3/vendor/google/cloud-core/src/RequestWrapperTrait.php 中调用,并在第 135 行的 /home/httpd/idxv3/vendor/google/auth/src/CredentialsLoader.php 中定义' 在 /home/httpd/idxv3/vendor/google/cloud-core/src/RequestWrapper.php:362
不确定身份验证为何会导致问题。
【问题讨论】:
标签: php api google-cloud-storage