Release Notes
Announcements
cos:GetService. For more authorization, see CAM-supported business APIs.Function Name | Description | Example code |
Querying the Bucket List | Querying the List of All Buckets Under the Specified Account |
qcloud_cos::CosAPI InitCosAPI() {uint64_t appid = 12500000000;std::string region = "ap-guangzhou";// Region of the bucket, see https://www.tencentcloud.com/document/product/436/62?from_cn_redirect=1std::string secret_id = "************************************"; // User's SecretId. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1std::string secret_key = "************************************"; // User's SecretKey. It is recommended to use sub-account keys, with authorization following the least privilege principle to mitigate usage risks. For information on how to obtain sub-account keys, see https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1qcloud_cos::CosConfig config(appid, secret_id, secret_key, region);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
qcloud_cos::CosAPI InitCosAPI() {// You need to have obtained the temporary key results: tmp_secret_id, tmp_secret_key,// For generating temporary keys, see https://www.tencentcloud.com/document/product/436/14048?from_cn_redirect=1#cos-sts-sdkuint64_t appid = 12500000000;std::string region = "ap-guangzhou";std::string tmp_secret_id = "************************************";std::string tmp_secret_key = "************************************";std::string tmp_token = "token";qcloud_cos::CosConfig config(appid, tmp_secret_id, tmp_secret_key, region);config.SetTmpToken(tmp_token);qcloud_cos::CosAPI cos_tmp(config);return cos_tmp;}
CosResult CosAPI::GetService(const GetServiceReq& req, GetServiceResp* resp)
void GetService(qcloud_cos::CosAPI& cos) {qcloud_cos::GetServiceReq req;qcloud_cos::GetServiceResp resp;qcloud_cos::CosResult result = cos.GetService(req, &resp);std::cout << "===================GetService====================="<< std::endl;PrintResult(result, resp);const qcloud_cos::Owner& owner = resp.GetOwner();const std::vector<qcloud_cos::Bucket>& buckets = resp.GetBuckets();std::cout << "owner.m_id=" << owner.m_id << ", owner.display_name=" << owner.m_display_name << std::endl;for (std::vector<qcloud_cos::Bucket>::const_iterator itr = buckets.begin();itr != buckets.end(); ++itr) {const qcloud_cos::Bucket& bucket = *itr;std::cout << "Bucket name=" << bucket.m_name<< ", location=" << bucket.m_location<< ", create_date=" << bucket.m_create_date << std::endl;}std::cout << "=========================================================" << std::endl;}
Parameter Name | Description | Type |
req | Querying bucket list request. | GetServiceReq |
resp | Querying bucket list response. | GetServiceResp |
Member or Function | Description | Parameter Type |
GetXCosRequestId | Obtain the request ID. | string |
GetOwner | Owner holder information. | struct |
GetBuckets | Bucket list information. | vector |
Member functions | Description | Return Type |
IsSucc | Indicates whether the operation is successful; returns true for success, false for failure. | bool |
GetHttpStatus | Obtain the HTTP status code. | int |
GetErrorCode | Obtain the error code when the request fails. | string |
GetErrorMsg | Obtain the error message when the request fails. | string |
GetXCosRequestId | Obtain the request ID. | string |
void PrintResult(const qcloud_cos::CosResult& result, const qcloud_cos::BaseResp& resp) {if (result.IsSucc()) {std::cout << "Request Succ." << std::endl;std::cout << resp.DebugString() << std::endl;} else {std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "HttpStatus=" << result.GetHttpStatus() << std::endl;std::cout << "ErrorCode=" << result.GetErrorCode() << std::endl;std::cout << "ErrorMsg=" << result.GetErrorMsg() << std::endl;std::cout << "ResourceAddr=" << result.GetResourceAddr() << std::endl;std::cout << "XCosRequestId=" << result.GetXCosRequestId() << std::endl;std::cout << "XCosTraceId=" << result.GetXCosTraceId() << std::endl;}}
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan