通过阅读本文,您可以了解通过服务端SDK调用OpenAPI管理智能媒体服务云剪辑工程的示例代码。

示例代码

您可以通过阿里云OpenAPI开发者门户在线调试。

import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Credential, { Config } from '@alicloud/credentials';
const Client = require('@alicloud/ice20201109').default;

// 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
// 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。配置方法请参见:https://help.aliyun.com/document_detail/378664.html

const cred = new Credential();
const iceClient = new Client(new $OpenApi.Config({
  credential: cred,
  endpoint: 'ice.cn-shanghai.aliyuncs.com'
}));

// 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
// const iceClient = new Client(new $OpenApi.Config({
//   accessKeyId: '<yourAccessKeyId>',
//   accessKeySecret: '<yourAccessKeySecret>',
//   endpoint: 'ice.cn-shanghai.aliyuncs.com'
// }));

// 创建云剪辑工程
iceClient.createEditingProject({
    Title: "测试工程名字",
    Description: "测试工程描述",
    Timeline: "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"****9b4d7cf14dc7b83b0e801cbe****\"}]}]}",
    CoverUrl: "http://xxxx/coverUrl.jpg"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 获取单个云剪辑工程
iceClient.getEditingProject({
    ProjectId: "42221ca594154d2fafa2842ecb85****"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 修改云剪辑工程
iceClient.updateEditingProject({
    ProjectId: "42221ca594154d2fafa2842ecb85****",
    Timeline: "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"9b4d7cf14dc7b83b0e801cbe****\"},{\"MediaId\":\"9b4d7cf14dc7b83b0e801cbe****\"},]}]}"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 删除云剪辑工程
iceClient.deleteEditingProjects({
    ProjectId: "42221ca594154d2fafa2842ecb85****"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 搜索云剪辑工程
iceClient.deleteEditingProjects({
    ProjectId: "42221ca594154d2fafa2842ecb85****"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

相关接口