tencent cloud

该页面目前只支持英文,你浏览的语言正在准备中。
关闭
全部产品文档
最后更新时间:2025-03-24 10:22:59
Java
最后更新时间: 2025-03-24 10:22:59

Overview

Welcome to Tencent Cloud Software Development Kit (SDK) 3.0, a companion tool for the TencentCloud API 3.0 platform. Currently, it supports products such as CVM, VPC and CBS. All cloud services and products will be integrated here for access in the future. The new version of SDK is unified and features the same SDK usage, API call methods, error codes and return packet formats for different languages. To make it easier for Java developers to debug and access the APIs of Tencent Cloud products, this document describes the Tencent Cloud SDK for Java and provides a simple example of using the SDK for the first time, helping you quickly get the SDK and start calling.

Dependent Environment

1. Dependent environment: JDK version 7 or higher.
2. Activate the corresponding product in the Tencent Cloud Console.
3. Get the SecretID, SecretKey and endpoint. The general format of endpoint is *.tencentcloudapi.com. For example, the call address of CVM is cvm.tencentcloudapi.com. For details, see the documentation of the specific product.

Installation

Obtain the security credentials before installing the SDK for Java. Before using the TencentCloud API for the first time, you need to first apply for security credentials in the Tencent Cloud Console, including SecretID and SecretKey. SecretID is used to identify the API caller, while SecretKey is used to encrypt the signature string and verify it on the server. You must keep the SecretKey private and avoid disclosure.

Installing via Maven (Recommended)

Installing via Maven is the recommended way to use the SDK for Java. Maven is a dependency management tool for Java that supports the dependencies your project requires and installs them into your project. For more information on Maven, see Maven's official website.
1. Go to Maven's official website to download the corresponding Maven installation package for your system and install.
2. Add Maven dependencies to your project by adding the following dependencies in Maven's pom.xml:
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java-intl-en</artifactId>
<!-- go to https://search.maven.org/search?q=tencentcloud-sdk-java-intl-en and get the latest version. -->
<!-- Please query the latest version at https://search.maven.org/search?q=tencentcloud-sdk-java-intl-en -->
<version>3.0.3</version>
</dependency>
3. For reference methods, see the example.

Example

Take the API for querying available instances as an example:
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
// Import the client of the corresponding product module
import com.tencentcloudapi.cvm.v20170312.CvmClient;
// Import the request response class corresponding to the request API
import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest;
import com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse;

public class DescribeInstances
{
public static void main(String [] args) {
try{
// Instantiate an authentication object. The Tencent Cloud account `secretId` and `secretKey` need to be passed in as the input parameters
Credential cred = new Credential("secretId", "secretKey");

// Instantiate the client object of the requested product (with CVM as an example)
ClientProfile clientProfile = new ClientProfile();
clientProfile.setSignMethod(ClientProfile.SIGN_TC3_256);
CvmClient client = new CvmClient(cred, "ap-guangzhou", clientProfile);

// Instantiate a request object
DescribeInstancesRequest req = new DescribeInstancesRequest();

// Call the API you want to access through the client object. You need to pass in the request object
DescribeInstancesResponse resp = client.DescribeInstances(req);

// A string return packet in JSON format is output
System.out.println(DescribeInstancesRequest.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}

}
}

More Examples

You can find more detailed examples in the examples directory of the GitHub repository.

本页内容是否解决了您的问题?
您也可以 联系销售 提交工单 以寻求帮助。

文档反馈

联系我们

联系我们,为您的业务提供专属服务。

技术支持

如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

7x24 电话支持
中国香港
+852 800 906 020 (免费)
美国
+1 844 606 0804 (免费)
英国
+44 808 196 4551 (免费)
加拿大
+1 888 605 7930 (免费)
澳大利亚
+61 1300 986 386 (免费)
EdgeOne 热线
+852 300 80699
更多本地服务热线陆续新增中