API | Operation | Description |
Querying a bucket list | Queries the list of all buckets under a specified account |
using COSXML.Model.Tag;using COSXML.Model.Service;using COSXML.Auth;using System;using COSXML;using System.Collections.Generic;namespace COSSnippet{public class GetServiceModel {private CosXml cosXml;GetServiceModel() {CosXmlConfig config = new CosXmlConfig.Builder().SetRegion("COS_REGION") // Set the default region. For abbreviations of COS regions, visit https://www.tencentcloud.com/document/product/436/6224?from_cn_redirect=1..Build();string secretId = "SECRET_ID"; // SecretId of the TencentCloud API. For more information about how to obtain the API key, see https://console.tencentcloud.com/cam/capi.string secretKey = "SECRET_KEY"; // SecretKey of the TencentCloud API. For more information about how to obtain the API key, see https://console.tencentcloud.com/cam/capi.long durationSecond = 600; // Validity period of the request signature in secondsQCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId,secretKey, durationSecond);this.cosXml = new CosXmlServer(config, qCloudCredentialProvider);}/// Get the bucket list.public void GetService(){//.cssg-snippet-body-start:[get-service]try{GetServiceRequest request = new GetServiceRequest();// Execute the requestGetServiceResult result = cosXml.GetService(request);// Get the list of all buckets.List<ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets;}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}//.cssg-snippet-body-end}/// Get the list of buckets residing in this region.public void GetRegionalService(){//.cssg-snippet-body-start:[get-regional-service]try{GetServiceRequest request = new GetServiceRequest();string region = "ap-guangzhou";request.host = $"cos.{region}.myqcloud.com";// Execute the requestGetServiceResult result = cosXml.GetService(request);// Get the list of all buckets.List<ListAllMyBuckets.Bucket> allBuckets = result.listAllMyBuckets.buckets;}catch (COSXML.CosException.CosClientException clientEx){// Request failedConsole.WriteLine("CosClientException: " + clientEx);}catch (COSXML.CosException.CosServerException serverEx){// Request failedConsole.WriteLine("CosServerException: " + serverEx.GetInfo());}//.cssg-snippet-body-end}// .cssg-methods-pragmastatic void Main(string[] args){GetServiceModel m = new GetServiceModel();/// Get the bucket list.m.GetService();/// Get the list of buckets residing in this region.m.GetRegionalService();// .cssg-methods-pragma}}}
Was this page helpful?