All Products
Search
Document Center

ApsaraVideo Media Processing:Manage tags of a media asset

Last Updated:Aug 21, 2023

ApsaraVideo Media Processing (MPS) does not support global tag management in media libraries. Tags of each media asset are independently set for the media asset. This topic describes how to add tags to and remove tags from a media asset.

Manage tags of a media asset

MPS allows you to manage tags by using MPS SDKs or calling API operations. For more information about how to install MPS SDKs for different programming languages, see Install Alibaba Cloud SDK for Java, Install Alibaba Cloud SDK for Python, and Alibaba Cloud SDK for PHP. For more information about the sample code, see the following text. For more information about how to call API operations, see the Directly call API operations to manage tags of a media asset section of this topic.

Note

In the following example, MPS SDK for PHP is used.

Use the SDK to call API operations to manage tags of a media asset

  • Add a tag

    You can call the AddMediaTag and DeleteMediaTag operations to add and remove a single tag. To add or remove multiple tags at a time, call the UpdateMedia operation. For more information about the parameters that are used to add a tag, see AddMediaTag. The following sample code provides an example:

    <?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
         * We recommend that you set the protocol parameter to HTTPS in a production environment.
         */
        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();
    
  • Remove a tag

    <?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
         * We recommend that you set the protocol parameter to HTTPS in a production environment.
         */
        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();
    

Directly call API operations to manage tags of a media asset

Note

You can directly call API operations in OpenAPI Explorer to manage tags of a media asset.

The following table describes the API operations that are used to manage tags of a media asset.

Feature

Operation

Add a tag

AddMediaTag

Remove a tag

DeleteMediaTag