全部产品

媒资分类

本文为您提供了.NET SDK媒资分类模块相关功能的API调用示例,包含创建分类、删除分类、修改分类、查寻分类及其子分类。

初始化客户端

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

创建分类

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                AddCategoryRequest request = new AddCategoryRequest();
                // 父分类ID,若不填,则默认生成一级分类,根节点分类ID为 -1
                request.ParentId = -1;
                // 分类名称
                request.CateName = "catename";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                AddCategoryResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                Console.WriteLine("CateId = " + response.Category.CateId);
                Console.WriteLine("CateName = " + response.Category.CateName);
                Console.WriteLine("ParentId = " + response.Category.ParentId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

修改分类

调用UpdateCategory接口,完成修改分类功能。

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                UpdateCategoryRequest request = new UpdateCategoryRequest();
                // 请设置真实分类ID
                request.CateId = -1;
                // 分类名称
                request.CateName = "new catename";
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                UpdateCategoryResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

删除分类

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                DeleteCategoryRequest request = new DeleteCategoryRequest();
                // 设置真实分类ID
                request.CateId = -1;
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                DeleteCategoryResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}

查询分类及其子分类

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

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

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.Sample
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                // 构造请求
                GetCategoriesRequest request = new GetCategoriesRequest();
                // 分类ID,若不填,则默认获取根节点及其子分类,根节点分类ID为-1
                request.CateId = -1;
                request.PageNo = 1;
                request.PageSize = 10;
                // 初始化客户端
                DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
                // 发起请求,并得到 response
                GetCategoriesResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                // 分类信息
                Console.WriteLine("Category.CateId = " + response.Category1.CateId);
                Console.WriteLine("Category.CateName = " + response.Category1.CateName);
                Console.WriteLine("Category.ParentId = " + response.Category1.ParentId);
                Console.WriteLine("SubTotal = " + response.SubTotal);
                // 子分类列表
                foreach (var subcategory in response.SubCategories)
                {
                    Console.WriteLine("subcategory.CateId = " + subcategory.CateId);
                    Console.WriteLine("subcategory.CateName = " + subcategory.CateName);
                    Console.WriteLine("subcategory.ParentId = " + subcategory.ParentId);
                }
            }
            catch (ServerException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (ClientException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}