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.

import com.aliyuncs.vod.model.v20170321.AddCategoryRequest;
import com.aliyuncs.vod.model.v20170321.AddCategoryResponse;

/*Method for creating a category*/
public static AddCategoryResponse addCategory(DefaultAcsClient client) throws Exception {
    AddCategoryRequest request = new AddCategoryRequest();
    // Sets the parent category ID. If you do not set this parameter, a level-1 category is generated. The root node category ID is -1.
    request.setParentId(-1L);
    // Sets the category name.
    request.setCateName("CateName");
    return client.getAcsResponse(request);
}

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    AddCategoryResponse response = new AddCategoryResponse();
    try {
        response = addCategory(client);
        // The information about the created category.
        System.out.print("ParentId = " + response.getCategory().getParentId() + "\n");
        System.out.print("CateId = " + response.getCategory().getCateId() + "\n");
        System.out.print("CateName = " + response.getCategory().getCateName() + "\n");
        System.out.print("Level = " + response.getCategory().getLevel() + "\n");
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Modify a category

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

import com.aliyuncs.vod.model.v20170321.UpdateCategoryRequest;
import com.aliyuncs.vod.model.v20170321.UpdateCategoryResponse;

/*Method for modifying a category*/
public static UpdateCategoryResponse updateCategory(DefaultAcsClient client) throws Exception {
    UpdateCategoryRequest request = new UpdateCategoryRequest();
    // Sets the category ID. The specified category ID must correspond to an existing category.
    request.setCateId(-1L);
    // Sets the category name.
    request.setCateName("CateName");
    return client.getAcsResponse(request);
}

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    UpdateCategoryResponse response = new UpdateCategoryResponse();
    try {
        response = updateCategory(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Delete a category

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

import com.aliyuncs.vod.model.v20170321.DeleteCategoryRequest;
import com.aliyuncs.vod.model.v20170321.DeleteCategoryResponse;

/*Method for deleting a category*/
public static DeleteCategoryResponse deleteCategory(DefaultAcsClient client) throws Exception {
    DeleteCategoryRequest request = new DeleteCategoryRequest();
    // Specifies the ID of the category to be deleted.
    request.setCateId(-1L);
    return client.getAcsResponse(request);
}

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    DeleteCategoryResponse response = new DeleteCategoryResponse();
    try {
        response = deleteCategory(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

Query a category and its subcategories

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

import com.aliyuncs.vod.model.v20170321.GetCategoriesRequest;
import com.aliyuncs.vod.model.v20170321.GetCategoriesResponse;

/*Call example*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    GetCategoriesResponse response = new GetCategoriesResponse();
    try {
        // Sets the category ID. The specified category ID must correspond to an existing category.
        Long cateId = -1L;
        // Sets the page number.
        Long pageNo = 1L;
        // Sets the number of data records per page.
        Long pageSize = 10L;
        response = getCategories(client, cateId, pageNo, pageSize);
        // The specified category information.
        System.out.print("ParentId = " + response.getCategory1().getParentId() + "\n");
        System.out.print("CateId = " + response.getCategory1().getCateId() + "\n");
        System.out.print("CateName = " + response.getCategory1().getCateName() + "\n");
        System.out.print("Level = " + response.getCategory1().getLevel() + "\n");
        System.out.print("SubTotal = " + response.getSubTotal()+ "\n");
        // The list of subcategories in the current category.
        for (GetCategoriesResponse.Category category : response.getSubCategories()) {
            System.out.print("SubCategories.ParentId = " + category.getParentId() + "\n");
            System.out.print("SubCategories.CateId = " + category.getCateId() + "\n");
            System.out.print("SubCategories.CateName = " + category.getCateName() + "\n");
            System.out.print("SubCategories.Level = " + category.getLevel() + "\n");
        }
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

/*Method for querying a category and its subcategories*/
public static GetCategoriesResponse getCategories(DefaultAcsClient client, Long cateId, Long pageNo, Long pageSize) throws Exception {
    GetCategoriesRequest request = new GetCategoriesRequest();
    request.setCateId(cateId);
    request.setPageNo(pageNo);
    request.setPageSize(pageSize);
    return client.getAcsResponse(request);
}