tencent cloud

All product documents
Last updated: 2025-03-24 10:22:59
Java
Last updated: 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.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon