全部產品
Search
文件中心

Intelligent Media Services:內容庫管理

更新時間:Nov 02, 2024

通過閱讀本文,您可以瞭解通過服務端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://www.alibabacloud.com/help/zh/sdk/developer-reference/v2-manage-node-js-access-credentials

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.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);
});

// 擷取媒資內容資訊
iceClient.getMediaInfo({
    MediaId : 'e76bd08-9555-429f-9aca-17ff8983****'
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

// 更新媒體資訊
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);
});


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

// 列出媒資基礎資訊
iceClient.listMediaBasicInfos({
    MaxResults: 10
}).then(function (data) {
  console.log(data.body);
}, function (err) {
  console.log('Error:' + err);
});

相關介面