Content library management

更新时间:
复制 MD 格式

This topic provides sample code that shows how to use a server-side software development kit (SDK) to call OpenAPI operations and manage the content library of Intelligent Media Services.

Sample code

To debug API calls online, use the Alibaba Cloud OpenAPI Developer Portal.

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

// An Alibaba Cloud account AccessKey has full access permissions for all APIs. Use a Resource Access Management (RAM) user for API access or daily O&M.
// This example shows how to save the AccessKey ID and AccessKey secret in environment variables. For more information, see 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'
}));

// To hard-code the AccessKey ID and AccessKey secret, use the following code. However, do not save the AccessKey ID and AccessKey secret in your project code. This can cause an AccessKey leak and threaten the security of all resources in your account.
// const iceClient = new Client(new $OpenApi.Config({
//   accessKeyId: '<yourAccessKeyId>',
//   accessKeySecret: '<yourAccessKeySecret>',
//   endpoint: 'ice.cn-shanghai.aliyuncs.com'
// }));

// Register a resource in the content library
iceClient.registerMediaInfo({
    InputURL : 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4',
    MediaType : 'video',
    Businesstype : 'video',
    Title : 'default_title'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// Get information about a media asset
iceClient.getMediaInfo({
    MediaId : 'e76bd08-9555-429f-9aca-17ff8983****'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// Update media information
iceClient.updateMediaInfo({
    MediaId : '76bd08-9555-429f-9aca-17ff8983****',
    CoverURL : "http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.jpg"
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});


// Delete media information
iceClient.deleteMediaInfos({
    MediaIds : '****e76bd08-9555-429f-9aca-17ff8983****'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// List basic information about media assets
iceClient.listMediaBasicInfos({
    MaxResults: 10
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

Related API operations