媒资分类

本文为您提供了Java SDK媒资分类模块相关功能的API调用示例,包含创建分类、删除分类、修改分类、获取分类。

初始化客户端

使用前请先初始化客户端,请参见初始化

创建分类

调用AddCategory接口,完成创建分类功能。

接口参数和返回字段请参见AddCategory。调用示例如下:

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

/*创建分类函数*/
public static AddCategoryResponse addCategory(DefaultAcsClient client) throws Exception {
    AddCategoryRequest request = new AddCategoryRequest();
    // 父分类ID,若不填,则默认生成一级分类,根节点分类ID为-1
    request.setParentId(-1L);
    // 分类名称
    request.setCateName("CateName");
    return client.getAcsResponse(request);
}

/*以下为调用示例*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    AddCategoryResponse response = new AddCategoryResponse();
    try {
        response = addCategory(client);
        // 创建成功的分类信息
        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");
}

更新分类

调用UpdateCategory接口,完成更新分类功能。

接口参数和返回字段请参见UpdateCategory。调用示例如下:

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

/*修改分类函数*/
public static UpdateCategoryResponse updateCategory(DefaultAcsClient client) throws Exception {
    UpdateCategoryRequest request = new UpdateCategoryRequest();
    // 请设置真实分类ID
    request.setCateId(-1L);
    // 分类名称
    request.setCateName("CateName");
    return client.getAcsResponse(request);
}

/*以下为调用示例*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    UpdateCategoryResponse response = new UpdateCategoryResponse();
    try {
        response = updateCategory(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

删除分类

调用DeleteCategory接口,完成删除分类功能。

接口参数和返回字段请参见DeleteCategory。调用示例如下:

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

/*删除分类函数*/
public static DeleteCategoryResponse deleteCategory(DefaultAcsClient client) throws Exception {
    DeleteCategoryRequest request = new DeleteCategoryRequest();
    // 请设置待删除分类ID
    request.setCateId(-1L);
    return client.getAcsResponse(request);
}

/*以下为调用示例*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your  AccessKeySecret>");
    DeleteCategoryResponse response = new DeleteCategoryResponse();
    try {
        response = deleteCategory(client);
    } catch (Exception e) {
        System.out.print("ErrorMessage = " + e.getLocalizedMessage());
    }
    System.out.print("RequestId = " + response.getRequestId() + "\n");
}

获取分类及其子分类

调用GetCategories接口,完成获取分类及其子分类功能。

接口参数和返回字段请参见GetCategories。调用示例如下:

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

/*以下为调用示例*/
public static void main(String[] argv) {
    DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your  AccessKeySecret>");
    GetCategoriesResponse response = new GetCategoriesResponse();
    try {
        // 请设置真实分类ID
        Long cateId = -1L;
        // 翻页页号
        Long pageNo = 1L;
        // 每页返回条数
        Long pageSize = 10L;
        response = getCategories(client, cateId, pageNo, pageSize);
        // 指定的分类信息
        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");
        // 当前分类的子分类列表
        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");
}

/*查询分类及其子分类函数*/
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);
}