标签管理

媒体库不提供全局的标签管理和设置,每个媒体的标签都是独立的。本文为您介绍如何为媒体文件添加和删除标签。

功能使用

媒体处理支持通过SDK或API管理标签。SDK安装请参见Java SDKPython SDKPHP SDK,示例代码见下文。如需通过API使用功能,请参见直接调用API管理标签

说明

本文以PHP语言为例。

SDK调用API管理标签

  • 添加标签

    标签的API支持单个标签的添加和删除,如果要一次设置多个标签,可以通过更新媒体-基本信息实现。添加标签的详细参数说明请参见更新媒体-添加标签,示例代码如下:

    <?php
    namespace AlibabaCloud\SDK\Sample;
    
    use AlibabaCloud\SDK\Mts\V20140618\Mts;
    use AlibabaCloud\Darabonba\Env\Env;
    use AlibabaCloud\Tea\Tea;
    use AlibabaCloud\Tea\Utils\Utils;
    use AlibabaCloud\Tea\Console\Console;
    
    use Darabonba\OpenApi\Models\Config;
    use AlibabaCloud\SDK\Mts\V20140618\Models\AddMediaTagRequest;
    
    
    class Sample {
    
        /**
         * @param string $accessKeyId
         * @param string $accessKeySecret
         * @param string $regionId
         * @return Mts
         * 正式环境下 建议 protocol = "HTTPS";
         */
        public static function createClient($accessKeyId, $accessKeySecret, $regionId){
            $config = new Config([]);
            $config->accessKeyId = $accessKeyId;
            $config->accessKeySecret = $accessKeySecret;
            $config->regionId = $regionId;
            $config->protocol = "HTTP";
            return new Mts($config);
        }
    
        /**
         * @return void
         */
        public static function main(){
            $client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
            $request = new AddMediaTagRequest([
                "mediaId" => "3e6149d5ad2dc3e4******",
                "tag" => "tag1"
            ]);
            $response = $client->addMediaTag($request);
            Console::log(Utils::toJSONString(Tea::merge($response->body)));
        }
    
    }
    $path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
    if (file_exists($path)) {
        require_once $path;
    }
    Sample::main();
    
  • 删除标签

    <?php
    namespace AlibabaCloud\SDK\Sample;
    
    use AlibabaCloud\SDK\Mts\V20140618\Mts;
    use AlibabaCloud\Darabonba\Env\Env;
    use AlibabaCloud\Tea\Tea;
    use AlibabaCloud\Tea\Utils\Utils;
    use AlibabaCloud\Tea\Console\Console;
    
    use Darabonba\OpenApi\Models\Config;
    use AlibabaCloud\SDK\Mts\V20140618\Models\DeleteMediaTagRequest;
    
    
    class Sample {
    
        /**
         * @param string $accessKeyId
         * @param string $accessKeySecret
         * @param string $regionId
         * @return Mts
         * 正式环境下 建议 protocol = "HTTPS";
         */
        public static function createClient($accessKeyId, $accessKeySecret, $regionId){
            $config = new Config([]);
            $config->accessKeyId = $accessKeyId;
            $config->accessKeySecret = $accessKeySecret;
            $config->regionId = $regionId;
            $config->protocol = "HTTP";
            return new Mts($config);
        }
    
        /**
         * @return void
         */
        public static function main(){
            $client = self::createClient(Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_ID"), Env::getEnv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"), 'cn-shanghai');
            $request = new DeleteMediaTagRequest([
                "mediaId" => "3e6149d5ad2dc3e4******",
                "tag" => "tag1"
            ]);
            $response = $client->deleteMediaTag($request);
            Console::log(Utils::toJSONString(Tea::merge($response->body)));
        }
    
    }
    $path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
    if (file_exists($path)) {
        require_once $path;
    }
    Sample::main();
    

直接调用API管理标签

说明

直接调用API是指直接在OpenAPI门户调用该接口对标签进行管理。

下表为标签管理对应的接口。

功能

接口

添加标签

更新媒体-添加标签

删除标签

更新媒体-删除标签