内容库管理

通过阅读本文,您可以了解通过服务端SDK调用OpenAPI管理智能媒体服务内容库的示例代码。

使用说明

目前仅支持通过OSS文件注册媒资内容。

示例代码

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

<?php

require_once '../ice-20201109/autoload.php';

use AlibabaCloud\SDK\ICE\V20201109\ICE;
use AlibabaCloud\SDK\ICE\V20201109\Models;
use AlibabaCloud\SDK\ICE\V20201109\Models\RegisterMediaInfoRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\GetMediaInfoRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\UpdateMediaInfoRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\DeleteMediaInfosRequest;
use AlibabaCloud\SDK\ICE\V20201109\Models\ListMediaBasicInfosRequest;
use Darabonba\OpenApi\Models\Config;

try{

    // 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
    // 本示例以将AccessKey ID和 AccessKey Secret保存在环境变量为例说明。配置方法请参见:https://help.aliyun.com/document_detail/311677.html
    $credential = new Credential([]);
    $config = new Config([
     'credential' => $credential,
     'endpoint' => 'ice.cn-shanghai.aliyuncs.com'
    ]);
    // 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
    // $config->accessKeyId = '<yourAccessKeyId>';
    // $config->accessKeySecret = '<yourAccessKeySecret>';
    $client = new ICE($config);

    // 注册媒资内容
    $request = new RegisterMediaInfoRequest();
    $request->inputURL = 'http://example-bucket.oss-cn-shanghai.aliyuncs.com/example.mp4';
    $request->mediaType = 'audio';
    $request->businesstype = 'audio';
    $request->title = 'default_title';
    $response = $client->registerMediaInfo($request);
    var_dump($response);
    $mediaId = $response->body->mediaId;

    // 获取单个内容
    $request = new GetMediaInfoRequest();
    $request->mediaId = $mediaId;
    $response = $client->getMediaInfo($request);
    var_dump($response);

    // 修改内容信息
    $request = new UpdateMediaInfoRequest();
    $request->mediaId = $mediaId;
    $request->coverURL = "https://guixin-test-bucket.oss-cn-shanghai.aliyuncs.com/image/timg.jpg";
    $response = $client->updateMediaInfo($request);
    var_dump($response);

    // 删除内容信息
    $request = new DeleteMediaInfosRequest();
    $request->mediaIds = $mediaId;
    $response = $client->deleteMediaInfos($request);
    var_dump($response);

    // 检索媒资信息
    $request = new ListMediaBasicInfosRequest();
    $request->maxResults = 10;
    $response = $client->listMediaBasicInfos($request);
    var_dump($response);

} catch (TeaUnableRetryError $e) {
    var_dump($e->getMessage());
    var_dump($e->getErrorInfo());
    var_dump($e->getLastException());
    var_dump($e->getLastRequest());
}

相关接口