淘宝客API调用折扣商品搜索及商品详情示例代码

淘宝客API调用折扣商品搜索及商品详情示例代码

淘宝API C#.NET SDK地址
http://open.taobao.com/doc/detail.htm?id=112

引用:

using Top.Api;

using Top.Api.Request;

using Top.Api.Response;

using Top.Api.Domain;

using System.Reflection;

using System.Collections.Generic;

调用taobao.tbk.dg.material.optional接口,筛选含优惠券、高折扣的商品,支持关键词、价格区间、折扣率等筛选条件:

复制代码
string url = "http://gw.api.taobao.com/router/rest";
# 封装好API供应商demo url=o0b.cn/ibrad  前往体验API:o0b.cn/ibrad
    string appkey = "*******";
    string appsecret = "***********************************";
    protected void Page_Load(object sender, EventArgs e)
    {        
        ITopClient client = new DefaultTopClient(url, appkey, appsecret);
        TaobaokeItemsGetRequest req = new TaobaokeItemsGetRequest();
        req.Fields = "num_iid,click_url";
        req.Nick = "dapeng031115";
        req.PageNo = 1;
        req.Keyword = "折扣";
        TaobaokeItemsGetResponse response = client.Execute(req);

        int l;
        if (response.TotalResults < 5)
        {
            l = Convert.ToInt16(response.TotalResults);
        }
        else
        {
            l = 5;
        }

        List<TaobaokeItem> tbis = response.TaobaokeItems;
        string[] LieMing = { "ClickUrl", "NumIid", "PicUrl", "Price", "Title" };
        DataTable dt = new DataTable();
        for (int i = 0; i < LieMing.Length; i++)
        {
            dt.Columns.Add(LieMing[i].ToString(), typeof(string));
        }
        for (int i = 0; i < l; i++)
        {
            DataRow dr = dt.NewRow();
            dr["ClickUrl"] = tbis[i].ClickUrl.ToString();
            Item tbdi = DetailProduct(tbis[i].NumIid.ToString());
            for (int j = 2; j < LieMing.Length; j++)
            {
                //用属性名称取得类中属性的值
                PropertyInfo ProInfo = tbdi.GetType().GetProperty(LieMing[j].ToString());
                dr[LieMing[j]] = ProInfo.GetValue(tbdi, null).ToString();
            }
            dt.Rows.Add(dr);
        }
        Repeater1.DataSource = dt;
        Repeater1.DataBind();
    }
    //根据商品ID获得商品详情
    public Item DetailProduct(string numiid)
    {
        string sessionKey = "";
        ITopClient client = new DefaultTopClient(url, appkey, appsecret);
        ItemGetRequest reqd = new ItemGetRequest();
        reqd.Fields = "detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,approve_status,postage_id,product_id,auction_point,property_alias,item_img,prop_img,sku,video,outer_id,is_virtual";
        reqd.NumIid = Convert.ToInt64(numiid);
        ItemGetResponse responsed = client.Execute(reqd, sessionKey);
        Item tbdi = responsed.Item;
        return tbdi;
    }
    protected string getsubstring(string s, int l)
    {
        string a = "";
        if (s.Length < l + 1)
        { a = s; }
        else
        {
            a = s.Substring(0, l) + "...";
        }
        return a;
    }

通过以上代码,可快速实现淘宝客折扣商品搜索和商品详情获取,适配选品、比价、导购等常见业务场景。

相关推荐
mldong1 小时前
C# 开发者也有自己的轻量工作流引擎了:NuGet 装包,5 分钟跑通一条审批流
后端·c#·.net
kruptos2 小时前
分布式系统怎么“选主“?Raft 共识一次讲清
开发语言·分布式·php·共识算法
吴声子夜歌2 小时前
ApacheCommons——commons-cli(命令行参数解析)
java·开发语言·apache
benchmark_cc3 小时前
REST API 和 Python SDK 应该怎么选?量化交易数据接口选型实战
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash
王的宝库3 小时前
Go 项目结构:从单文件到标准工程布局
开发语言·后端·golang
Tairitsu_H3 小时前
[C++] 深入理解红黑树:封装set与map
开发语言·c++·set·map·红黑树·模拟实现
泡海椒4 小时前
JQuick-Curl 性能分析:并发场景下的性能表现与调优,第三方接口调用不只要快写也要稳跑
java·开发语言·okhttp
小智老师PMP4 小时前
2026深度解析|PMP第八版与NPDP核心侧重点本质区别(管理类证书怎么选)
开发语言·分布式·算法·职场和发展·产品经理
samble5 小时前
从零搭建工业控制系统(二十二):线程安全与并发控制
c#·wpf·并发·mvvm·线程安全·工业控制
江畔柳前堤5 小时前
前台·中台·后台:2026年AI原生时代的架构全景图
开发语言·人工智能·算法·机器学习·架构·scala·ai-native