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

时间:13-02-01 栏目:网站开发 作者:admin 评论:1 点击: 4,584 次

C#代码

淘宝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;
代码:

string url = "http://gw.api.taobao.com/router/rest";
    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;
    }

声明: 本文由( admin )原创编译,转载请保留链接: 淘宝客API调用折扣商品搜索及商品详情示例代码

淘宝客API调用折扣商品搜索及商品详情示例代码:目前有1 条留言

  1. 沙发
    xiaoleidianji:

    太感谢你了,解决了我的一个难题!感激不尽!

    2013-04-08 3:18 pm [回复]

发表评论


------====== 本站公告 ======------
联系信息:
lxq73061#qq.com qq:583964941
支付宝:https://me.alipay.com/lxq73061
相关插件程序等信息均会在站内发布,敬请关注。

读者排行