淘宝客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;
    }

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

相关推荐
FuckPatience21 小时前
C# 使用内存映射文件实现进程间通信
c#
a程序小傲21 小时前
蚂蚁Java面试被问:注解的工作原理及如何自定义注解
java·开发语言·python·面试
似水এ᭄往昔1 天前
【C++】--封装红⿊树实现mymap和myset
开发语言·数据结构·c++·算法·stl
charlie1145141911 天前
嵌入式现代C++教程:C++98——从C向C++的演化(3)
c语言·开发语言·c++·笔记·学习·嵌入式
TAEHENGV1 天前
创建目标模块 Cordova 与 OpenHarmony 混合开发实战
android·java·开发语言
程序员zgh1 天前
C语言 指针用法与区别(指针常量、常量指针、指针函数、函数指针、二级指针)
c语言·开发语言·jvm·c++
是一个Bug1 天前
如何阅读JDK源码?
java·开发语言
石头dhf1 天前
大模型配置
开发语言·python
inferno1 天前
JavaScript 基础
开发语言·前端·javascript
派大鑫wink1 天前
【Day15】集合框架(三):Map 接口(HashMap 底层原理 + 实战)
java·开发语言