全部产品
云市场

媒资分类

更新时间:2018-12-30 17:19:31

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

创建分类

接口参数和返回字段请参考 AddCategory

  1. import com.aliyuncs.vod.model.v20170321.AddCategoryRequest;
  2. import com.aliyuncs.vod.model.v20170321.AddCategoryResponse;
  3. /*创建分类函数*/
  4. public static AddCategoryResponse addCategory(DefaultAcsClient client) throws Exception {
  5. AddCategoryRequest request = new AddCategoryRequest();
  6. // 父分类ID,若不填,则默认生成一级分类,根节点分类ID为-1
  7. request.setParentId(-1L);
  8. // 分类名称
  9. request.setCateName("CateName");
  10. return client.getAcsResponse(request);
  11. }
  12. /*以下为调用示例*/
  13. public static void main(String[] argv) {
  14. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  15. AddCategoryResponse response = new AddCategoryResponse();
  16. try {
  17. response = addCategory(client);
  18. // 创建成功的分类信息
  19. System.out.print("ParentId = " + response.getCategory().getParentId() + "\n");
  20. System.out.print("CateId = " + response.getCategory().getCateId() + "\n");
  21. System.out.print("CateName = " + response.getCategory().getCateName() + "\n");
  22. System.out.print("Level = " + response.getCategory().getLevel() + "\n");
  23. } catch (Exception e) {
  24. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  25. }
  26. System.out.print("RequestId = " + response.getRequestId() + "\n");
  27. }

修改分类

接口参数和返回字段请参考 UpdateCategory

  1. import com.aliyuncs.vod.model.v20170321.UpdateCategoryRequest;
  2. import com.aliyuncs.vod.model.v20170321.UpdateCategoryResponse;
  3. /*修改分类函数*/
  4. public static UpdateCategoryResponse updateCategory(DefaultAcsClient client) throws Exception {
  5. UpdateCategoryRequest request = new UpdateCategoryRequest();
  6. // 请设置真实分类ID
  7. request.setCateId(-1L);
  8. // 分类名称
  9. request.setCateName("CateName");
  10. return client.getAcsResponse(request);
  11. }
  12. /*以下为调用示例*/
  13. public static void main(String[] argv) {
  14. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  15. UpdateCategoryResponse response = new UpdateCategoryResponse();
  16. try {
  17. response = updateCategory(client);
  18. } catch (Exception e) {
  19. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  20. }
  21. System.out.print("RequestId = " + response.getRequestId() + "\n");
  22. }

删除分类

接口参数和返回字段请参考 DeleteCategory

  1. import com.aliyuncs.vod.model.v20170321.DeleteCategoryRequest;
  2. import com.aliyuncs.vod.model.v20170321.DeleteCategoryResponse;
  3. /*删除分类函数*/
  4. public static DeleteCategoryResponse deleteCategory(DefaultAcsClient client) throws Exception {
  5. DeleteCategoryRequest request = new DeleteCategoryRequest();
  6. // 请设置待删除分类ID
  7. request.setCateId(-1L);
  8. return client.getAcsResponse(request);
  9. }
  10. /*以下为调用示例*/
  11. public static void main(String[] argv) {
  12. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  13. DeleteCategoryResponse response = new DeleteCategoryResponse();
  14. try {
  15. response = deleteCategory(client);
  16. } catch (Exception e) {
  17. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  18. }
  19. System.out.print("RequestId = " + response.getRequestId() + "\n");
  20. }

查询分类及其子分类

接口参数和返回字段请参考 GetCategories

  1. import com.aliyuncs.vod.model.v20170321.GetCategoriesRequest;
  2. import com.aliyuncs.vod.model.v20170321.GetCategoriesResponse;
  3. /*以下为调用示例*/
  4. public static void main(String[] argv) {
  5. DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  6. GetCategoriesResponse response = new GetCategoriesResponse();
  7. try {
  8. // 请设置真实分类ID
  9. Long cateId = -1L;
  10. // 翻页页号
  11. Long pageNo = 1L;
  12. // 每页返回条数
  13. Long pageSize = 10L;
  14. response = getCategories(client, cateId, pageNo, pageSize);
  15. // 指定的分类信息
  16. System.out.print("ParentId = " + response.getCategory1().getParentId() + "\n");
  17. System.out.print("CateId = " + response.getCategory1().getCateId() + "\n");
  18. System.out.print("CateName = " + response.getCategory1().getCateName() + "\n");
  19. System.out.print("Level = " + response.getCategory1().getLevel() + "\n");
  20. System.out.print("SubTotal = " + response.getSubTotal()+ "\n");
  21. // 当前分类的子分类列表
  22. for (GetCategoriesResponse.Category category : response.getSubCategories()) {
  23. System.out.print("SubCategories.ParentId = " + category.getParentId() + "\n");
  24. System.out.print("SubCategories.CateId = " + category.getCateId() + "\n");
  25. System.out.print("SubCategories.CateName = " + category.getCateName() + "\n");
  26. System.out.print("SubCategories.Level = " + category.getLevel() + "\n");
  27. }
  28. } catch (Exception e) {
  29. System.out.print("ErrorMessage = " + e.getLocalizedMessage());
  30. }
  31. System.out.print("RequestId = " + response.getRequestId() + "\n");
  32. }
  33. /*查询分类及其子分类函数*/
  34. public static GetCategoriesResponse getCategories(DefaultAcsClient client, Long cateId, Long pageNo, Long pageSize) throws Exception {
  35. GetCategoriesRequest request = new GetCategoriesRequest();
  36. request.setCateId(cateId);
  37. request.setPageNo(pageNo);
  38. request.setPageSize(pageSize);
  39. return client.getAcsResponse(request);
  40. }