我正在使用PHP AWS SDK,并希望列出S3中可用的所有存储桶.
我找到了几个看起来很有前途的文档块:
http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/get_bucket_list
http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.S3.Iterator.ListBucketsIterator.html
以下是我正在尝试的,使用AWS Service Builder初始化S3客户端......
use Aws\Common\Aws; // Instantiate an S3 client $aws = Aws::factory(array( 'key' => "MY_KEY", 'secret' => "MY_SECRET")); $s3 = $aws->get('s3'); $s3->get_bucket_list();
不幸的是,当我运行代码时,我被告知它没有了解'get_buckets_list'是什么.更具体地说它
Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Command was not found matching GetBucketList' in vendor/guzzle/guzzle/src/Guzzle/Service/Client.php:87
所以我的问题如下:
我看错了文件吗?
某处有其他文件吗?
如何使用PHP AWS SDK获取存储桶列表?
Ja͢ck.. 9
可以在此处找到此调用的文档.
$result = $s3->listBuckets(array()); foreach ($result['Buckets'] as $bucket) { echo $bucket['Name'], PHP_EOL; }
我怀疑你混合了两个不同的API :)