Search in sources :

Example 1 with DefaultCredentialsProvider

use of com.tencentcloudapi.common.provider.DefaultCredentialsProvider in project tencentcloud-sdk-java by TencentCloud.

the class CredentialManager method main.

public static void main(String[] args) {
    try {
        // 通过凭证提供链得到一个认证对象
        Credential cred = new DefaultCredentialsProvider().getCredentials();
        // 实例化要请求产品(以cvm为例)的client对象,依次传入Credential、地域
        CvmClient client = new CvmClient(cred, "ap-guangzhou");
        // 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。
        DescribeInstancesRequest req = new DescribeInstancesRequest();
        // 通过client对象调用DescribeInstances方法发起请求。注意请求方法名与请求对象是对应的
        // 返回的resp是一个DescribeInstancesResponse类的实例,与请求对象对应
        DescribeInstancesResponse resp = client.DescribeInstances(req);
        // 输出json格式的字符串回包
        System.out.println(DescribeInstancesResponse.toJsonString(resp));
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DefaultCredentialsProvider(com.tencentcloudapi.common.provider.DefaultCredentialsProvider) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)

Aggregations

Credential (com.tencentcloudapi.common.Credential)1 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 DefaultCredentialsProvider (com.tencentcloudapi.common.provider.DefaultCredentialsProvider)1 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)1 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)1 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)1