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

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

相关推荐
多加点辣也没关系2 小时前
JavaScript|第4章:类型转换
开发语言·javascript
聪慧的水蜜桃2 小时前
【YFIOs】用C#开发硬件之设备上云
开发语言·c#
yqcoder2 小时前
httpOnly 是什么,又有什么用?
开发语言·前端·javascript
wuqingshun3141593 小时前
重写equals而不重写hashCode,会出什么问题?
java·开发语言
飞猪~3 小时前
LangChain python 版本 第一集
开发语言·python·langchain
李燚5 小时前
Go 项目怎么组织:DDD 4 层 vs MVC vs 脚本式
开发语言·golang·mvc·ddd·agent框架·eino
2zcode5 小时前
免费开源项目文档:基于MATLAB图像处理的啤酒瓶口缺陷检测系统设计与实现
开发语言·图像处理·matlab
人工智能时代 准备好了吗6 小时前
AI回答内容进入率监测:引用识别、文本匹配与语义判断
开发语言·人工智能·python
LONGZETECH6 小时前
新能源汽车动力电池检测仿真教学系统:C/S 分层架构与数字化实训落地全解析
大数据·c语言·开发语言·人工智能·架构·系统架构·汽车
郝学胜-神的一滴6 小时前
中级OpenGL教程 013:渲染器类架构设计与逐帧渲染流程详解
开发语言·c++·unity·游戏引擎·图形渲染·opengl·unreal