All Products
Search
Document Center

Media asset category

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Create a category

For more information about the request and response parameters, see AddCategory.

function addCategory($client, $cateName, $parentId=-1) {
    $request = new vod\AddCategoryRequest();
    $request->setCateName($cateName); 
    $request->setParentId($parentId); 
    $request->setAcceptFormat('JSON'); 
    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $addRes = addCategory($client, 'Category Name');
    var_dump($addRes);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Modify a category

For more information about the request and response parameters, see UpdateCategory.

function updateCategory($client, $cateId, $cateName) {
    $request = new vod\UpdateCategoryRequest();
    $request->setCateId($cateId); 
    $request->setCateName($cateName); // Sets the category name.
    $request->setAcceptFormat('JSON'); 
    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $updateRes = updateCategory($client, '<Category ID>', 'New Category Name');
    var_dump($updateRes);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Delete a category

For more information about the request and response parameters, see DeleteCategory.

// If you delete a video category, its subcategories are deleted recursively, including level-2 and level-3 categories. Proceed with caution.
function deleteCategory($client, $cateId) {
    $request = new vod\DeleteCategoryRequest();
    $request->setCateId($cateId); 
    $request->setAcceptFormat('JSON'); 
    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $delRes = deleteCategory($client, '<Category ID>');
    var_dump($delRes);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}

Query a category and its subcategories

For more information about the request and response parameters, see GetCategories.

// Obtains the information about the specified category and a list of its subcategories.
function getCategories($client, $cateId=-1, $pageNo=1, $pageSize=10) {
    $request = new vod\GetCategoriesRequest();
    $request->setCateId($cateId); // Sets the category ID. The default value -1 indicates the root node category ID.
    $request->setPageNo($pageNo); 
    $request->setPageSize($pageSize); 
    $request->setAcceptFormat('JSON'); 
    return $client->getAcsResponse($request);
}

try {
    $client = initVodClient('<AccessKeyId>', '<AccessKeySecret>');
    $getRes = getCategories($client, '<Category Id>');
    var_dump($getRes);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}