本示例介绍如何使用Alibaba Cloud SDK for Java调用SearchTemplate接口查询搜索自定义转码模板。

前提条件

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-mts</artifactId>
    <version>2.7.2</version>
</dependency>

示例代码

package com.ygx.program;

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;
import com.ygx.testprogram.ECSConfig;

public class TestSearchTemplate {

    public static void main(String[] args) {
        // 创建SearchTemplate实例并初始化
        DefaultProfile profile = DefaultProfile.getProfile(
                ECSConfig.REGION_ID,            // 地域ID
                ECSConfig.ACCESSKEY_ID,        // 您的AccessKey ID
                ECSConfig.ACCESSKEYSECRET_ID );    // 您的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());
        }
    }
}
说明 更多媒体处理服务接口内容,请参见API概述