概要
SDK のインストール方法および使用方法の詳細については、「メディアライブラリ SDK-PHP」 をご参照ください。
メディアリポジトリでは、グローバルタグの管理と設定をサポートしていません。 各メディアセット内のタグは一意です。 ユーザーは、同じタグを持つすべてのメディアセットを照会するメディアセット API の検索を行えます。
タグ関連の API は、1 つのタグの追加と削除をサポートしています。 一度に複数のタグを設定するには、UpdateMedia を使用します。
タグの追加
パラメーターの詳細については、「API reference > Media APIs > AddMediaTag」をご参照ください。
include_once 'aliyun-php-sdk-core/Config.php';
use Mts\Request\V20140618 as Mts;
$accessKeyID = 'test'; //eplace the value with your AccessKeyID
$accessKeySecret = 'test'; //Replace the value with your AccessKeySecret
$profile = DefaultProfile::getProfile('cn-hangzhou',
$accessKeyID,
$accessKeySecret);
$client = new DefaultAcsClient($profile);
function addMediaTag($client, $mediaID, $tag)
{
$request = new Mts\AddMediaTagRequest();
$request->setAcceptFormat('JSON');
$request->setMediaId($mediaID);
$request->setTag($tag);
$response = $client->getAcsResponse($request);
return $response;
}
$mediaID = 'test'; //Replace the value with your desired media ID
//No result is returned from the API. Capture exceptions to check whether execution succeeds
try {
addMediaTag($client, $mediaID, "testtag");
} catch(ClientException $e) {
print_r('ClientException:'."\n");
print_r($e);
} catch (ServerException $e) {
print_r('ServerException:'."\n");
print_r($e);
}
タグの削除
パラメーターの詳細については、「API reference > Media APIs > DeleteMediaTag」をご参照ください。
function deleteMediaTag($client, $mediaID, $tag)
{
$request = new Mts\DeleteMediaTagRequest();
$request->setAcceptFormat('JSON');
$request->setMediaId($mediaID);
$request->setTag($tag);
$response = $client->getAcsResponse($request);
return $response;
}
$mediaID = 'test'; //Replace the value with your desired media ID
//No result is returned from the API. Capture exceptions to check whether execution succeeds
try {
deleteMediaTag($client, $mediaID, "testtag");
} catch(ClientException $e) {
print_r('ClientException:'."\n");
print_r($e);
} catch (ServerException $e) {
print_r('ServerException:'."\n");
print_r($e);
}