edit-icon download-icon

Tag management

Last Updated: Feb 14, 2018

Back to Overview

  • Overview

    For details about how to install and use the SDK, see Media library SDK-PHP.

    The media repository does not provide global tag management and setting. Tags of each media set are independent. You can search for APIs of a media set to query all media sets that have the same tags.

    The tag-related APIs support addition and deletion of a single tag. You can use UpdateMedia to set multiple tags at a time.

  • Add a tag

    For details about the parameters, see API reference > Media APIs > Add a media tag.

    1. include_once 'aliyun-php-sdk-core/Config.php';
    2. use Mts\Request\V20140618 as Mts;
    3. $accessKeyID = 'test'; // Replace the value with your AccessKeyID
    4. $accessKeySecret = 'test'; // Replace the value with your AccessKeySecret
    5. $profile = DefaultProfile::getProfile('cn-hangzhou',
    6. $accessKeyID,
    7. $accessKeySecret);
    8. $client = new DefaultAcsClient($profile);
    1. function addMediaTag($client, $mediaID, $tag)
    2. {
    3. $request = new Mts\AddMediaTagRequest();
    4. $request->setAcceptFormat('JSON');
    5. $request->setMediaId($mediaID);
    6. $request->setTag($tag);
    7. $response = $client->getAcsResponse($request);
    8. return $response;
    9. }
    10. $mediaID = 'test'; // Replace the value with your desired media ID
    11. // No result is returned from the API. Capture exceptions to check whether execution succeeds
    12. try {
    13. addMediaTag($client, $mediaID, "testtag");
    14. } catch (ClientException $e) {
    15. print_r('ClientException:'."\n");
    16. print_r($e);
    17. } catch (ServerException $e) {
    18. print_r('ServerException:'."\n");
    19. print_r($e);
    20. }
  • Delete a tag

    For details about the parameters, see API reference > Media APIs > Delete a media tag.

    1. function deleteMediaTag($client, $mediaID, $tag)
    2. {
    3. $request = new Mts\DeleteMediaTagRequest();
    4. $request->setAcceptFormat('JSON');
    5. $request->setMediaId($mediaID);
    6. $request->setTag($tag);
    7. $response = $client->getAcsResponse($request);
    8. return $response;
    9. }
    10. $mediaID = 'test'; // Replace the value with your desired media ID
    11. // No result is returned from the API. Capture exceptions to check whether execution succeeds
    12. try {
    13. deleteMediaTag($client, $mediaID, "testtag");
    14. } catch (ClientException $e) {
    15. print_r('ClientException:'."\n");
    16. print_r($e);
    17. } catch (ServerException $e) {
    18. print_r('ServerException:'."\n");
    19. print_r($e);
    20. }
Thank you! We've received your feedback.