eBay大中华区API开发者平台 开发者专区

搜 索
首页>API开发者平台>技术文档>如何获取我的店铺中所有的Category

技术文档

问题
如何获取我的店铺中所有的Category
解答
0
人觉得答案有帮助)

 

总述   

调用GetStore可将店铺中所有的Category按level返回。因为不同level间的Category错综复杂,需要使用递归算法进行检索。

 


详述

此C#例程使用了.NET SDK,用于检索店铺中所有的Category:

using eBay.Service.Core.Sdk; 
using eBay.Service.Core.Soap; 
using eBay.Service.Call; 
using eBay.Service.Util; 

namespace NETSDKSample 

    public class SDKSample 
    { 
        private void GetStore() 
        {  
            //set your credentials for the call  
            ApiContext context = new ApiContext(); 
            context.ApiCredential.ApiAccount.Developer = "devID"; 
            context.ApiCredential.ApiAccount.Application = "appID"; 
             context.ApiCredential.ApiAccount.Certificate = "certID"; 
            context.ApiCredential.eBayToken = "token"; 
            // Set the URL 
            context.SoapApiServerUrl ="https://api.sandbox.ebay.com/wsapi"; 
            // Set logging 
            context.ApiLogManager = new ApiLogManager(); 
            context.ApiLogManager.ApiLoggerList.Add(neweBay.Service.Util.FileLogger("Messages.log", true, true, true)); 
            context.ApiLogManager.EnableLogging = true; 
            // Set the version 
            context.Version = "571"; 
            //create call 
            GetStoreCall call = new GetStoreCall(context); 
            //get just the store categories 
            call.CategoryStructureOnly = true; 
            call.Execute();

            //iterate through the top level categories 
            foreach (StoreCustomCategoryType cat incall.Store.CustomCategories) 
            { 
                GetChildCategories(cat); 
            }

        }

        private void GetChildCategories(StoreCustomCategoryType cat) 
        { 
            //get the category name, ID and whether it is a leaf 
            long id = cat.CategoryID; 
            string name = cat.Name; 
            bool leaf = (cat.ChildCategory.Count == 0); 
            Console.WriteLine("id = " + id + " name = " + name + " leaf= "+ leaf);

            //condition to end the recursion 
            if (leaf) 
            { 
                return; 
            }

            //continue the recursion for each of the child categories 
            foreach (StoreCustomCategoryType childcat in cat.ChildCategory)
            { 
                GetChildCategories(childcat); 
            } 
        }

    }

}


 


答案对您有帮助吗?

是,对我很有帮助
否,没解决我的问题