Querying a Bucket List

Last updated: 2023-09-13 11:16:28

Feature Overview

This document provides an overview of APIs and SDK code samples for querying a bucket list.
API
Operation
Description
Querying the bucket list
Queries the list of all buckets under a specified account

Querying the bucket list

Note

This API (GET Service (List Buckets)) is used to query the list of all buckets under a specified account.

Method prototype

public Guzzle\Service\Resource\Model listBuckets();

Sample code

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //Replace it with the actual SecretId, which can be viewed and managed in the CAM console at https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //Replace it with the actual SecretKey, which can be viewed and managed in the CAM console at https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //Replace it with the actual region, which can be viewed in the console at https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\Cos\Client(
array(
'region' => $region,
'schema' => 'https', //Protocol header, default is http
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->listBuckets();
// Request successful
print_r($result);
} catch (\Exception $e) {
// Request failed
echo($e);
}

Sample response

Array
(
[data:protected] => Array
(
[Owner] => Array
(
[ID] => qcs::cam::uin/100000000001:uin/100000000001
[DisplayName] => 100000000001
)

[Buckets] => Array
(
[0] => Array
(
[Name] => examplebucket-1250000000
[Location] => ap-beijing
[CreationDate] => 2016-07-29T03:09:54Z
)

[1] => Array
(
[Name] => examplebucket2-1250000000
[Location] => ap-beijing
[CreationDate] => 2017-08-02T04:00:24Z
)

)

[RequestId] => NWE3YzgxZmFfYWZhYzM1MGFfMzc3MF9iOGY5OQ==
)

)

Response description

Parameter name
Parent Node
Description
Local Disk Types
Owner
-
Bucket owner information
Array
ID
Owner
Bucket owner ID
String
DisplayName
Owner
Bucket owner name
String
Buckets
-
A buckets list
Array
Bucket
Buckets
Bucket information
Array
Name
Bucket
Bucket Name
String
Location
Bucket
Name of bucket region
String
CreationDate
Bucket
Time of Bucket creation
String