SDK for Java 使用指南

最近更新时间:2020-09-10 16:23:16

SDK for Java 使用指南

安装Java SDK

添加模板

更新模板

删除模板

查询模板列表

查询模板详情

创建任务

置顶任务

删除任务

查询任务列表

查询任务详情

查询任务队列信息

更新任务队列状态

查询任务META信息

安装Java SDK

1.git 安装

git clone https://github.com/KscSDK/ksc-sdk-java.git    
mvn clean install

2.工程使用sdk

建议使用Maven构建自己的项目,导入ksc-sdk-java,添加ksc-sdk-java-kvs的依赖。

新建maven项目
进入到pom文件下,进行如下配置
<dependencies>
    <dependency>
        <groupId>com.ksyun</groupId>
        <artifactId>ksc-sdk-java-kvs</artifactId>
        <version>0.3.8</version>
    </dependency>
</dependencies>

3.通过文件配置及管理密钥

本地文件配置:
 ~/.aws/credentials on Linux, OS X or unix
C:\Users\USERNAME\.aws\credentials on Windows
该文件包含下述内容:
[default]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key
如不通过本地文件读入ak和sk信息,则需要在执行的类文件中增加以下代码:
AWSCredentials credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);

SDK介绍和使用

在调用接口前,先初始化 KSCKVSJsonClient,如下用例:
KSCKVSJsonClient ksc = new KSCKVSJsonClient();
//可传入AWSCredentials参数 如:KSCKVSJsonClient ksc = new KSCKVSJsonClient(credentials);
ksc.setEndpoint("http://kvs.cn-beijing-6.api.ksyun.com/");
字符集:utf-8

注:接口的传递的参数及返回值请参考点播转码API

创建模板

  • 接口名

Preset

  • 调用方式
PresetRequest presetRequest = new PresetRequest();
String data = PresetSet("xxx");
presetRequest.setData(data);
KvsErrResult presetResult = ksc.Preset(presetRequest);
//请求内容生成接口
private static String PresetSet(String preset) throws JSONException {
    String presettype = "xxx";
    JSONObject data = new JSONObject();
    JSONObject param = new JSONObject();
    JSONObject video = new JSONObject();
    JSONObject audio = new JSONObject();
    JSONArray logos = new JSONArray();
    data.put("Preset", "xxx");
    data.put("PresetType", "xxx");
    data.put("Description", "xxx");
    video.put("vr", "13");
    video.put("vb", "780000");
    video.put("vcodec", "h264");
    for (int i = 0; i < 4; i++) {
        JSONArray logo = new JSONArray();
        for (int j = 0; j < 2; j++) {
            JSONObject tmp = new JSONObject();
            tmp.put("url", String.valueOf(i) + ":" + String.valueOf(j));
            tmp.put("ss", i + j);
            logo.put(tmp);
        }
        logos.put(logo);
    }
    audio.put("ar", "xxx");
    audio.put("ab", "xxx");
    audio.put("acodec", "aac");
    audio.put("an", 0);
    param.put("f", "xxx");
    param.put("VIDEO", video);
    param.put("AUDIO", audio);
    param.put("LOGOS", logos);
    data.put("Param", param);
    return data.toString();
}

更新模板

  • 接口名

UpdatePreset

  • 调用方式
UpdatePresetRequest presetRequest = new UpdatePresetRequest();
String data = PresetSet("xxx");
presetRequest.setData(data1);
KvsErrResult presetResult = ksc.UpdatePreset(presetRequest);

删除模板

  • 接口名

DelPreset

  • 调用方式
DeletePresetRequest deletePresetRequest = new DeletePresetRequest();
deletePresetRequest.setPreset("xxx");
KvsErrResult deletePresetResult = ksc.DelPreset(deletePresetRequest);

查询模板列表

  • 接口名

GetPresetList

  • 调用方式
GetListRequest gitlistrequest = new GetListRequest();
gitlistrequest.setWithDetail(1);
KvsResult getpresetlistResult = ksc.GetPresetList(gitlistrequest);

查询模板详情

  • 接口名

GetPresetDetail

  • 调用方式
GetPresetDetailRequest getPresetDetailRequest = new GetPresetDetailRequest();
getPresetDetailRequest.setPreset("xxx");
GetPresetDetailResult getPresetDetailResult = ksc.GetPresetDetail(getPresetDetailRequest);

创建任务

  • 接口名

CreateTask

  • 调用方式
CreateTaskRequest createTaskRequest = new CreateTaskRequest();
String data2 = setTask("xxx", "xxx", "xxx", "xxx");
createTaskRequest.setData(data2);
CreateTasklResult createTasklResult = ksc.CreateTask(createTaskRequest);
//请求内容生成接口
private static String setTask(String preset, String dst_bucket, String dst_object_key, String src_object_key)
        throws JSONException {
    JSONObject data = new JSONObject();
    data.put("Preset", preset);
    data.put("SrcInfo", TaskSrcInfo(dst_bucket, src_object_key));
    data.put("DstBucket", dst_bucket);
    data.put("DstObjectKey", dst_object_key);
    data.put("DstDir", "");
    data.put("IsTop", 0);
    data.put("DstAcl", "public-read");
    data.put("CbUrl", "");
    data.put("CbMethod", "POST");
    data.put("ExtParam", "");
    return data.toString();
}

置顶任务

  • 接口名

TopTaskByTaskID

  • 调用方式
TopTaskByTaskIDRequest topTaskByTaskIDRequest = new TopTaskByTaskIDRequest();
topTaskByTaskIDRequest.setTaskID("xxx");
KvsErrResult TopTaskByTaskIDResult = ksc.TopTaskByTaskID(topTaskByTaskIDRequest);

删除任务

  • 接口名

DelTaskByTaskID

  • 调用方式
DelTaskByTaskIDRequest delTaskByTaskIDRequest = new DelTaskByTaskIDRequest();
delTaskByTaskIDRequest.setTaskID("xxx");
KvsErrResult DelTaskByTaskIDResult = ksc.DelTaskByTaskID(delTaskByTaskIDRequest);

查询任务列表

  • 接口名

GetTaskList

  • 调用方式
GetTaskListRequest getTaskListRequest = new GetTaskListRequest();    
getTaskListRequest.setStartDate(20200202);
getTaskListRequest.setEndDate(20200220);
getTaskListRequest.setTaskStatus("succ");
getTaskListRequest.setErrorCode("3255");
GetTaskListResult getTaskListResult = ksc.GetTaskList(getTaskListRequest);

查询任务详情

  • 接口名

GetTaskByTaskID

  • 调用方式
GetTaskByTaskIDRequest getTaskByTaskIDRequest = new GetTaskByTaskIDRequest();
getTaskByTaskIDRequest.setTaskID("xxx");
GetTaskByTaskIDResult getTaskByTaskIDResult = ksc.GetTaskByTaskID(getTaskByTaskIDRequest);

查询任务队列信息

  • 接口名

QueryPipeline

  • 调用方式
QueryPipelineRequest queryPipelineRequest = new QueryPipelineRequest(); 
queryPipelineRequest.setPipelineName("usual"); 
QueryPipelineResult queryPipelineResult = ksc.QueryPipeline(queryPipelineRequest); 
System.out.println(queryPipelineResult);

更新任务队列状态

  • 接口名

UpdatePipeline

  • 调用方式
UpdatePipelineRequest updatePipelineRequest = new UpdatePipelineRequest(); 
updatePipelineRequest.setData(setPipeline("usual"));
KvsErrResult updatePipelineResult = ksc.UpdatePipeline(updatePipelineRequest); 
System.out.println(updatePipelineResult); //设置更新任务队列请求参数 private static String setPipeline(String PipelineName) { JSONObject data = new JSONObject(); data.put("PipelineName", PipelineName); data.put("State", "Active"); return data.toString(); }

查询任务META列表

  • 接口名

GetTaskMetaInfo

  • 调用方式
GetTaskMetaRequest getTaskMetaInfoRequest = new GetTaskMetaRequest();
getTaskMetaInfoRequest.setTaskID("xxx"); //需要是avinfo模板类型的任务
getTaskMetaInfoRequest.setStartDate(20200202);
GetTaskMetaResult getTaskMetaResult = ksc.GetTaskMetaInfo(getTaskMetaInfoRequest);
System.out.println(getTaskMetaResult);

同步获取META信息接口

  • 接口名

FetchMetaInfo

  • 调用方式
JSONObject data = new JSONObject();
    data.put("SrcPath","bkt-bj-youpin-video-kscn/daren/b911aecedd47b97b8d3c1214c758d62e.mp4");
    System.out.println(data);
    FetchMetaInfoRequest fetchMetaInfoRequest = new FetchMetaInfoRequest();
    fetchMetaInfoRequest.setData(data.toString());
    FetchMetaInfoResult fetchMetaInfoResult = ksc.FetchMetaInfo(fetchMetaInfoRequest);
    System.out.println(fetchMetaInfoResult.getMetaInfo());

金山云,开启您的云计算之旅

免费注册