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.
3. Get the SecretID, SecretKey and call address (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.
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</artifactId>
<version>3.0.0</version>
</dependency>
3. For reference methods, see the example.
Example
Take the API for querying available zones as an example:
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.cvm.v20170312.CvmClient;
import com.tencentcloudapi.cvm.v20170312.models.DescribeZonesRequest;
import com.tencentcloudapi.cvm.v20170312.models.DescribeZonesResponse;
public class DescribeZones
{
public static void main(String [] args) {
try{
Credential cred = new Credential("secretId", "secretKey");
CvmClient client = new CvmClient(cred, "ap-guangzhou");
DescribeZonesRequest req = new DescribeZonesRequest();
DescribeZonesResponse resp = client.DescribeZones(req);
System.out.println(DescribeZonesRequest.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.
Older SDK
We recommend that you use the new version of SDK. If you need an older version, add the following dependencies to your Maven's pom.xml:
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>qcloud-java-sdk</artifactId>
<version>2.0.6</version>
</dependency>
本页内容是否解决了您的问题?