全部产品
云市场

媒资分类

更新时间:2018-12-26 19:55:30

初始化客户端

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

创建分类

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

  1. from aliyunsdkvod.request.v20170321 import AddCategoryRequest
  2. def add_category(clt, cateName, parentId=-1):
  3. request = AddCategoryRequest.AddCategoryRequest()
  4. request.set_CateName(cateName)
  5. request.set_ParentId(parentId)
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. addRes = add_category(clt, 'Category Name')
  12. print(json.dumps(addRes, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

修改分类

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

  1. from aliyunsdkvod.request.v20170321 import UpdateCategoryRequest
  2. def update_category(clt, cateId, cateName):
  3. request = UpdateCategoryRequest.UpdateCategoryRequest()
  4. request.set_CateId(cateId)
  5. request.set_CateName(cateName)
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. updateRes = update_category(clt, '<cateId>', 'New Category Name')
  12. print(json.dumps(updateRes, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

删除分类

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

  1. from aliyunsdkvod.request.v20170321 import UpdateCategoryRequest
  2. # 删除视频分类,同时会删除其下级分类(包括二级分类和三级分类),请慎重操作
  3. def delete_category(clt, cateId):
  4. request = DeleteCategoryRequest.DeleteCategoryRequest()
  5. request.set_CateId(cateId)
  6. request.set_accept_format('JSON')
  7. response = json.loads(clt.do_action_with_exception(request))
  8. return response
  9. try:
  10. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  11. delRes = delete_category(clt, '<cateId>')
  12. print(json.dumps(delRes, ensure_ascii=False, indent=4))
  13. except Exception as e:
  14. print(e)
  15. print(traceback.format_exc())

查询分类及其子分类

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

  1. from aliyunsdkvod.request.v20170321 import GetCategoriesRequest
  2. def get_categories(clt, cateId=-1, pageNo=1, pageSize=10):
  3. request = GetCategoriesRequest.GetCategoriesRequest()
  4. request.set_CateId(cateId)
  5. request.set_PageNo(pageNo)
  6. request.set_PageSize(pageSize)
  7. request.set_accept_format('JSON')
  8. response = json.loads(clt.do_action_with_exception(request))
  9. return response
  10. try:
  11. clt = init_vod_client('<AccessKeyId>', '<AccessKeySecret>')
  12. getRes = get_categories(clt, '<cateId>')
  13. print(json.dumps(getRes, ensure_ascii=False, indent=4))
  14. except Exception as e:
  15. print(e)
  16. print(traceback.format_exc())