c#.net淘寶客基礎api練手日記

橙-景安伺服器代理發表於2018-09-03

下載地址:

最新淘寶客C#.NET基礎API程式碼和SDK

https://download.csdn.net/download/cplvfx/10643458

 

淘寶客基礎api練手日記

第一步:SDK 下載

http://open.taobao.com/doc.htm?spm=a219a.7386653.0.0.ae9foK&docId=101618&docType=1

SDK檔案目錄:

把下載好的SDK放到專案web的bin資料夾下

只放:TopSdk.dll 檔案即可

第二步:專案中引入SDK

第三步:獲取 App Key和App Secret

http://console.open.taobao.com/

 

第四步:cs檔案程式碼

淘寶客商品詳情(簡版)

http://open.taobao.com/api.htm?docId=24518&docType=2&scopeId=11655

    public partial class ceshi_taobaoke_api : System.Web.UI.Page
    {
        public static string appUrl = "	http://gw.api.taobao.com/router/rest";
        public static string appKey = "appKey";
        public static string appSecret = "appSecret";

        protected void Page_Load(object sender, EventArgs e)
        {

            Label1.Text =TaoBaoShow("524176904993",1L,"61.52.68.39","json")+"<br>";
            Label1.Text+="\n\n\n"+TaoBaoShow("524176904993",1L,"61.52.68.39","xml");


        }

        #region 淘寶客商品詳情(簡版)----------------------------
        /// <summary>
        /// 淘寶客商品詳情 (簡版)
        /// </summary>
        /// <param name="NumIids">商品ID串,用,分割,最大40個</param>
        /// <param name="Platform">	連結形式:1:PC,2:無線,預設:1</param>
        /// <param name="Ip">ip地址,影響郵費獲取,如果不傳或者傳入不準確,郵費無法精準提供</param>
        /// <param name="format">格式:XML或JSON</param>
        public static string TaoBaoShow(string NumIids, Int64 Platform, string Ip, string format)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret,format);
            TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
            req.NumIids =NumIids;
            req.Platform = Platform;
            req.Ip = Ip;
            TbkItemInfoGetResponse rsp = client.Execute(req);
            return rsp.Body;
        }
        #endregion

    }

第五步:返回資料

json 資料

{
	"tbk_item_info_get_response": {
		"results": {
			"n_tbk_item": [{
				"cat_leaf_name": "衛衣\/絨衫",
				"cat_name": "女裝\/女士精品",
				"item_url": "https:\/\/item.taobao.com\/item.htm?id=524176904993",
				"material_lib_type": "1",
				"nick": "FREEMEIGE原創自由派潮女裝",
				"num_iid": 524176904993,
				"pict_url": "https:\/\/img.alicdn.com\/bao\/uploaded\/i2\/102467811\/TB2AcJ3grFkpuFjy1XcXXclapXa_!!102467811.jpg",
				"provcity": "廣東 廣州",
				"reserve_price": "189",
				"seller_id": 102467811,
				"small_images": {
					"string": ["https:\/\/img.alicdn.com\/i1\/102467811\/TB2Br4DguJ8puFjy1XbXXagqVXa_!!102467811.jpg", "https:\/\/img.alicdn.com\/i1\/TB1TV50KpXXXXb.XVXXXXXXXXXX_!!0-item_pic.jpg", "https:\/\/img.alicdn.com\/i2\/102467811\/TB2uAx1gq8lpuFjy0FpXXaGrpXa_!!102467811.jpg", "https:\/\/img.alicdn.com\/i1\/102467811\/TB2ki9BXyKO.eBjSZPhXXXqcpXa_!!102467811.jpg"]
				},
				"title": "2018秋季新款 個性女裝寬鬆衛衣顯瘦原宿風斗篷外套加厚蝙蝠衫潮",
				"user_type": 0,
				"volume": 93,
				"zk_final_price": "189"
			}]
		},
		"request_id": "4ifd06xkqzre"
	}
}

xml資料

<?xml version="1.0" encoding="utf-8" ?>
<tbk_item_info_get_response>
    <results>
        <n_tbk_item>
            <cat_leaf_name>衛衣/絨衫</cat_leaf_name>
            <cat_name>女裝/女士精品</cat_name>
            <item_url>https://item.taobao.com/item.htm?id=524176904993</item_url>
            <material_lib_type>1</material_lib_type>
            <nick>FREEMEIGE原創自由派潮女裝</nick>
            <num_iid>524176904993</num_iid>
            <pict_url>https://img.alicdn.com/bao/uploaded/i2/102467811/TB2AcJ3grFkpuFjy1XcXXclapXa_!!102467811.jpg</pict_url>
            <provcity>廣東 廣州</provcity>
            <reserve_price>189</reserve_price>
            <seller_id>102467811</seller_id>
            <small_images>
                <string>https://img.alicdn.com/i1/102467811/TB2Br4DguJ8puFjy1XbXXagqVXa_!!102467811.jpg</string>
                <string>https://img.alicdn.com/i1/TB1TV50KpXXXXb.XVXXXXXXXXXX_!!0-item_pic.jpg</string>
                <string>https://img.alicdn.com/i2/102467811/TB2uAx1gq8lpuFjy0FpXXaGrpXa_!!102467811.jpg</string>
                <string>https://img.alicdn.com/i1/102467811/TB2ki9BXyKO.eBjSZPhXXXqcpXa_!!102467811.jpg</string>
            </small_images>
            <title>2018秋季新款 個性女裝寬鬆衛衣顯瘦原宿風斗篷外套加厚蝙蝠衫潮</title>
            <user_type>0</user_type>
            <volume>93</volume>
            <zk_final_price>189</zk_final_price>
        </n_tbk_item>
    </results>
    <request_id>hetegfay8x96</request_id>
</tbk_item_info_get_response>
<!--top011183249188.na62-->

下載地址:

最新淘寶客C#.NET基礎API程式碼和SDK

https://download.csdn.net/download/cplvfx/10643458

------------------------------------------------------------------------------

參考程式碼

標題:.net淘寶客基礎api

網址:http://www.51pcode.com/Article/Page/1383

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
 
namespace MvcWebApp.DataBase
{
    public class TaoDataProvider
    {
 
        public static string appKey = ConfigurationManager.AppSettings["appKey"].ToString();
        public static string appSecret = ConfigurationManager.AppSettings["appSecret"].ToString();
        public static string appUrl = "http://gw.api.taobao.com/router/rest";
 
        //淘寶官方介面說明:http://open.taobao.com/doc2/apiDetail.htm?spm=a219a.7395905.0.0.70naXx&scopeId=11655&apiId=26619
 
        /// <summary>
        /// 關鍵字查詢商品
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="queryKey"></param>
        /// <returns></returns>
        public static string query(int PageIndex, int PageSize, string queryKey)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret, "json");
            TbkItemGetRequest req = new TbkItemGetRequest();
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            req.Q = queryKey;
            req.Platform = 1L;
            req.PageNo = PageIndex;
            req.PageSize = PageSize;
            TbkItemGetResponse response = client.Execute(req);
            return response.Body;
        }
        /// <summary>
        /// 分頁查詢
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="queryKey"></param>
        /// <param name="totalCount"></param>
        /// <param name="pageNum"></param>
        /// <returns></returns>
        public static List<Top.Api.Domain.NTbkItem> query(int PageIndex, int PageSize, string queryKey, out long totalCount, out long pageNum)
        {
            totalCount = 0;
            pageNum = 0;
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
 
            TbkItemGetRequest req = new TbkItemGetRequest();
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            req.Q = queryKey;
            req.Platform = 1L;
            req.PageNo = PageIndex;
            req.PageSize = PageSize;
 
            TbkItemGetResponse response = client.Execute(req);
 
            totalCount = response.TotalResults;
            pageNum = (long)Math.Ceiling(totalCount / (double)PageSize);
            return response.Results;
        }
        /// <summary>
        /// 分頁查詢商品
        /// </summary>
        /// <param name="PageIndex">當前頁</param>
        /// <param name="PageSize">每頁多少條</param>
        /// <param name="queryKey">關鍵字</param>
        /// <param name="cat">後臺類目ID16,18</param>
        /// <param name="itemloc">所在地</param>
        /// <param name="sort">排序_des降序.排序_asc升序.排序銷量total_sales淘客佣金比率tk_rate累計推廣量tk_total_sales總支出佣金tk_total_commi</param>
        /// <param name="isTmall">是否商城商品</param>
        /// <param name="isOverseas">是否海外商品</param>
        /// <param name="startPrice">折扣價範圍下限</param>
        /// <param name="endPrice">折扣價範圍上限</param>
        /// <param name="startTkRate">淘客佣金比率上限</param>
        /// <param name="endTkRate">淘客佣金比率下限</param>
        /// <param name="totalCount">總條數</param>
        /// <param name="pageNum">總頁數</param>
        /// <returns></returns>
        public static List<Top.Api.Domain.NTbkItem> query(int PageIndex, int PageSize, string queryKey,
            string cat, string itemloc, string sort, bool? isTmall, bool? isOverseas, long? startPrice, long? endPrice,
            long? startTkRate, long? endTkRate,
            out long totalCount, out long pageNum)
        {
            totalCount = 0;
            pageNum = 0;
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
 
            TbkItemGetRequest req = new TbkItemGetRequest();
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            if (!string.IsNullOrWhiteSpace(queryKey)) req.Q = queryKey;
            req.Platform = 1;
            req.PageNo = PageIndex;
            req.PageSize = PageSize;
 
            if (!string.IsNullOrWhiteSpace(cat)) req.Cat = cat;//後臺類目ID16,18
            if (!string.IsNullOrWhiteSpace(itemloc)) req.Itemloc = itemloc;//所在地
            if (!string.IsNullOrWhiteSpace(sort)) req.Sort = sort;//"tk_rate_des";//排序
            if (isTmall.HasValue) req.IsTmall = isTmall;//是否商城商品
            if (isOverseas.HasValue) req.IsOverseas = isOverseas;//是否海外商品
            if (startPrice.HasValue) req.StartPrice = startPrice;//	折扣價範圍下限
            if (endPrice.HasValue) req.EndPrice = endPrice;
            if (startTkRate.HasValue) req.StartTkRate = startTkRate;//淘客佣金比率上限,如:1234表示12.34%
            if (endTkRate.HasValue) req.EndTkRate = endTkRate;
 
 
 
            TbkItemGetResponse response = client.Execute(req);
 
            totalCount = response.TotalResults;
            pageNum = (long)Math.Ceiling(totalCount / (double)PageSize);
            return response.Results;
        }
 
 
        /// <summary>
        /// 根據ID查詢單個商品
        /// </summary>
        /// <param name="ssid"></param>
        /// <returns></returns>
        public static string FindOne(string ssid)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret, "json");
            TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            req.Platform = 1L;
            req.NumIids = ssid;
            TbkItemInfoGetResponse rsp = client.Execute(req);
            return rsp.Body;
        }
        /// <summary>
        /// 根據ID查詢單個商品
        /// </summary>
        /// <param name="ssid">123,256,365(最多40個)</param>
        /// <returns></returns>
        public static List<Top.Api.Domain.NTbkItem> FindBySSID(string ssid)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            req.Platform = 1L;
            req.NumIids = ssid;
            TbkItemInfoGetResponse rsp = client.Execute(req);
            return rsp.Results;
        }
        /// <summary>
        /// 關聯商品查詢
        /// </summary>
        /// <param name="relate_type"></param>
        /// <param name="num_iid"></param>
        /// <param name="count"></param>
        /// <param name="platform"></param>
        /// <returns></returns>
        public static string FindListRelevance(int? relate_type, long? num_iid, int? count = 24, int? platform = 1)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret, "json");
            TbkItemRecommendGetRequest req = new TbkItemRecommendGetRequest();
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
 
            if (num_iid.HasValue)
                req.NumIid = num_iid.Value;
 
            //req.Cat = 123L;
            req.Count = count.Value;
            req.Platform = platform.Value;
            TbkItemRecommendGetResponse rsp = client.Execute(req);
            //Console.WriteLine(rsp.Body);
            return rsp.Body;
        }
        /// <summary>
        /// 關聯商品查詢
        /// </summary>
        /// <param name="relate_type"></param>
        /// <param name="num_iid"></param>
        /// <param name="count"></param>
        /// <param name="platform"></param>
        /// <returns></returns>
        public static List<Top.Api.Domain.NTbkItem> FindListRelate(int? relate_type, long? num_iid, int? count = 24, int? platform = 1)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkItemRecommendGetRequest req = new TbkItemRecommendGetRequest();
 
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url";
            //if (relate_type.HasValue)
            //    req.RelateType = relate_type.Value;
            if (num_iid.HasValue)
                req.NumIid = num_iid.Value;
 
            //req.Cat = 123L;
            req.Count = count.Value;
            req.Platform = platform.Value;
            TbkItemRecommendGetResponse rsp = client.Execute(req);
            //Console.WriteLine(rsp.Body);
            return rsp.Results;
        }
        /// <summary>
        /// 獲取淘寶客店鋪列表
        /// </summary>
        /// <param name="PageIndex">第幾頁</param>
        /// <param name="PageSize">每頁幾條</param>
        /// <param name="queryKey">關鍵字</param>
        /// <param name="start_credit">信用等級下限,1~20</param>
        /// <param name="end_credit">信用等級上限,1~20</param>
        /// <param name="start_commission_rate">淘客佣金比率下限,1~10000</param>
        /// <param name="end_commission_rate">淘客佣金比率上限,1~10000</param>
        /// <param name="start_total_action">店鋪商品總數下限</param>
        /// <param name="end_total_action">店鋪商品總數上限</param>
        /// <param name="start_auction_count">累計推廣商品下限</param>
        /// <param name="end_auction_count">累計推廣商品上限</param>
        /// <param name="totalCount">總數</param>
        /// <param name="pageNum">總頁數</param>
        /// <returns></returns>
        public static List<Top.Api.Domain.NTbkShop> FindShopsPagedList(long PageIndex, long PageSize, string queryKey,
            long? start_credit, long? end_credit, long? start_commission_rate, long? end_commission_rate,
            long? start_total_action, long? end_total_action, long? start_auction_count, long? end_auction_count,
            out long totalCount, out long pageNum)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkShopGetRequest req = new TbkShopGetRequest();
            req.Fields = "click_url,pic_url,seller_nick,shop_title,shop_url,user_id";
            if (!string.IsNullOrWhiteSpace(queryKey)) req.Q = queryKey;
            if (start_credit.HasValue) req.StartCredit = start_credit;
            if (end_credit.HasValue) req.EndCredit = end_credit;
 
            if (start_commission_rate.HasValue) req.StartCommissionRate = start_commission_rate;
            if (end_commission_rate.HasValue) req.EndCommissionRate = end_commission_rate;
 
            if (start_total_action.HasValue) req.StartTotalAction = start_total_action;
            if (end_total_action.HasValue) req.EndTotalAction = end_total_action;
 
            if (start_auction_count.HasValue) req.StartAuctionCount = start_auction_count;
            if (end_auction_count.HasValue) req.EndAuctionCount = end_auction_count;
 
            req.PageNo = PageIndex;
            req.PageSize = PageSize;
            TbkShopGetResponse rsp = client.Execute(req);
 
            totalCount = rsp.TotalResults;
            pageNum = (long)Math.Ceiling(totalCount / (double)PageSize);
            return rsp.Results;
 
 
        }
        /// <summary>
        /// 淘寶客店鋪關聯推薦查詢
        /// </summary>
        /// <param name="userid">賣家Id</param>
        /// <returns></returns>
        public static List<Top.Api.Domain.NTbkShop> GetShopRecommend(long userid)
        {
 
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkShopRecommendGetRequest req = new TbkShopRecommendGetRequest();
            req.Fields = "click_url,pict_url,seller_nick,shop_title,shop_type,shop_url,user_id";
            req.UserId = userid;
            req.Count = 20;
            req.Platform = 1;
            TbkShopRecommendGetResponse rsp = client.Execute(req);
            return rsp.Results;
 
        }
        /// <summary>
        /// 列舉正在進行中的定向招商的活動列表
        /// </summary>
        /// <returns></returns>
        public static List<Top.Api.Domain.TbkEvent> GetTbkUatmEvent(long? pageindex = 1, long? pageSize = 20)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkUatmEventGetRequest req = new TbkUatmEventGetRequest();
            req.PageNo = pageindex;
            req.PageSize = pageSize;
            req.Fields = "event_id,event_title,start_time,end_time";
            TbkUatmEventGetResponse rsp = client.Execute(req);
            return rsp.Results;
        }
        /// <summary>
        /// 獲取淘寶聯盟定向招商的寶貝資訊
        /// </summary>
        /// <param name="event_id"></param>
        /// <param name="pageindex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<Top.Api.Domain.UatmTbkItem> GetTbkUatmEventItem(long event_id, long? pageindex = 1, long? pageSize = 20)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkUatmEventItemGetRequest req = new TbkUatmEventItemGetRequest();
            req.Platform = 1L;
            req.PageSize = pageSize;
            //req.AdzoneId = 34567L;
            //req.Unid = unid;
            req.EventId = event_id;
            req.PageNo = pageindex;
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,type,status";
            TbkUatmEventItemGetResponse rsp = client.Execute(req);
            return rsp.Results;
 
        }
        /// <summary>
        /// 獲取淘寶聯盟選品庫列表
        /// </summary>
        /// <param name="type">預設值-1;選品庫型別,1:普通選品組,2:高傭選品組,-1,同時輸出所有型別的選品組</param>
        /// <param name="pageindex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<Top.Api.Domain.TbkFavorites> GetTbkUatmFavorites(long? type=-1, long? pageIndex = 1, long? pageSize = 20)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkUatmFavoritesGetRequest req = new TbkUatmFavoritesGetRequest();
            req.PageNo = pageIndex;
            req.PageSize = pageSize;
            req.Fields = "favorites_title,favorites_id,type";
            req.Type = type;
            TbkUatmFavoritesGetResponse rsp = client.Execute(req);
            return rsp.Results;
        }
        /// <summary>
        /// 指定選品庫id,獲取該選品庫的寶貝資訊
        /// </summary>
        /// <param name="FavoritesId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<Top.Api.Domain.UatmTbkItem> GetTbkUatmFavoritesItem(long? FavoritesId, long? pageIndex = 1, long? pageSize = 20)
        {
            ITopClient client = new DefaultTopClient(appUrl, appKey, appSecret);
            TbkUatmFavoritesItemGetRequest req = new TbkUatmFavoritesItemGetRequest();
            req.Platform = 1L;
            req.PageSize = pageSize;
            //req.AdzoneId = 34567L;
            //req.Unid = "3456";
            req.FavoritesId = FavoritesId;
            req.PageNo = pageIndex;
            req.Fields = "num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick,shop_title,zk_final_price_wap,event_start_time,event_end_time,tk_rate,status,type";
            TbkUatmFavoritesItemGetResponse rsp = client.Execute(req);
            return rsp.Results;
        }
 
 
    }
}

下載地址:

最新淘寶客C#.NET基礎API程式碼和SDK

https://download.csdn.net/download/cplvfx/10643458

相關文章