欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

c#.net淘宝客基础api练手日记

程序员文章站 2023-12-23 22:36:21
...

下载地址:

最新淘宝客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文件目录:

c#.net淘宝客基础api练手日记

把下载好的SDK放到项目web的bin文件夹下

只放:TopSdk.dll 文件即可

第二步:项目中引入SDK

c#.net淘宝客基础api练手日记

第三步:获取 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练手日记

下载地址:

最新淘宝客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练手日记

下载地址:

最新淘宝客C#.NET基础API代码和SDK

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

上一篇:

下一篇: