本示例介绍如何使用Alibaba Cloud SDK for Java调用SearchTemplate接口查询搜索自定义转码模板。
前提条件
在使用本教程前,请确保已完成以下操作:
- 使用Alibaba Cloud SDK for Java,您需要一个阿里云账号和访问密钥(AccessKey)。 请在阿里云控制台中的AccessKey管理页面上创建和查看您的AccessKey。
- 确保您已经安装了Alibaba Cloud SDK for Java,准确的SDK版本号,请参见 阿里云开发工具包(SDK)。
<project> <modelVersion>4.0.0</modelVersion> <groupId>java.demo</groupId> <artifactId>test</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core --> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.4.3</version> </dependency> <!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-mts --> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-mts</artifactId> <version>2.7.2</version> </dependency> </dependencies> </project>
示例代码
本文操作示例主要以代码形式体现,具体代码如下:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.*;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
public class TestSearchTemplate {
public static void main(String[] args) {
// 初始化请求参数
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // 地域ID
"<your-access-key-id>", // 您的AccessKey ID
"<your-access-key-secret>");// 您的AccessKey Secret
IAcsClient client = new DefaultAcsClient(profile);
SearchTemplateRequest request = new SearchTemplateRequest();
// 转码模板状态:All表示所有, Normal表示正常, Deleted表示已删除, 默认值:All
request.setState("All");
// 分页 默认:PageNumber = 1L ; PageSize = 10L
request.setPageNumber(1L);
request.setPageSize(10L);
try {
SearchTemplateResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
在文档使用中是否遇到以下问题
更多建议
匿名提交