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.

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
            {
                // Constructs a request.
                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.ParentId = -1;
                // Sets the category name.
                request.CateName = "catename";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Modify a category

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                UpdateCategoryRequest request = new UpdateCategoryRequest();
                // Sets the category ID. The specified category ID must correspond to an existing category.
                request.CateId = -1;
                // Sets the category name.
                request.CateName = "new catename";
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Delete a category

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                DeleteCategoryRequest request = new DeleteCategoryRequest();
                // Sets the category ID. The specified category ID must correspond to an existing category.
                request.CateId = -1;
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a 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());
            }
        }
    }
}

Query a category and its subcategories

For more information about the request and response parameters, see 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
            {
                // Constructs a request.
                GetCategoriesRequest request = new GetCategoriesRequest();
                // Sets the ID of the category whose subcategories are obtained. If you do not set this parameter, the subcategories of the root node category are obtained. The root node category ID is -1.
                request.CateId = -1;
                request.PageNo = 1;
                request.PageSize = 10;
                // Initializes the client.
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                GetCategoriesResponse response = client.GetAcsResponse(request);
                Console.WriteLine("RequestId = " + response.RequestId);
                // The category information.
                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);
                // The list of subcategories.
                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());
            }
        }
    }
}