001 package com.taobao.api;
002
003 import com.alibaba.fastjson.JSON;
004 import com.alibaba.fastjson.JSONObject;
005 import com.taobao.api.request.ItemGetRequest;
006 import com.taobao.api.request.ItemcatsGetRequest;
007 import com.taobao.api.request.ShopGetRequest;
008 import com.taobao.api.request.TaobaokeItemsGetRequest;
009 import com.taobao.api.response.ItemGetResponse;
010 import com.taobao.api.response.ItemcatsGetResponse;
011 import com.taobao.api.response.ShopGetResponse;
012 import com.taobao.api.response.TaobaokeItemsGetResponse;
013
014 public class APITest {
015 protected static String url = “http://gw.api.taobao.com/router/rest”;// 沙箱环境调用地址
016 // 正式环境需要设置为:http://gw.api.taobao.com/router/rest
017 // http://gw.api.tbsandbox.com/router/rest
018 protected static String appkey = “你的key”;
019 protected static String appSecret = “你的secret”;
020
021 public static void main(String[] args) {
022 // APITest.testItemGet();
023 // getShopInfo();
024 getItems();
025 // getItem();
026 }
027
028 /**
029 * 获取所有类别目录
030 /
031 public static void testItemGet() {
032 TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
033 ItemcatsGetRequest req = new ItemcatsGetRequest();
034 req.setFields(“cid,parent_cid,name,is_parent”);
035 req.setParentCid(0L);
036 // req.setCids(“18957,19562,”);
037 ItemcatsGetResponse response = null;
038 try {
039 response = client.execute(req);
040 } catch (ApiException e) {
041 e.printStackTrace();
042 }
043 }
044
045 /*
046 * sid 店铺编号。shop+sid.taobao.com即店铺地址,如shop123456.taobao.com
047 *
048 * @param cid
049 * 123456 店铺所属的类目编号
050 * @param nick
051 * 卖家昵称
052 * @param title
053 * 店铺标题
054 * @param desc
055 * 店铺描述
056 * @param bulletin
057 * 店铺公告
058 * @param pic_path
059 * 店标地址。返回相对路径,可以用"http://logo.taobao.com/shop-logo"来拼接成绝对路径
060 * @param created
061 * 开店时间。格式:yyyy-MM-dd HH:mm:ss
062 * @param modified
063 * 最后修改时间。格式:yyyy-MM-dd HH:mm:ss
064 * @param shop_score
065 * 店铺动态评分信息(item_score:商品描述评分;service_score:服务态度评分;delivery_score
066 * :发货速度评分;)
067 /
068 public static void getShopInfo() {
069 TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
070 ShopGetRequest req = new ShopGetRequest();
071 req.setFields(“shop_score,sid,cid,title,nick,desc,bulletin,pic_path,created,modified”);
072 req.setNick(“hemp619”);
073 ShopGetResponse response = null;
074 try {
075 response = client.execute(req);
076 } catch (ApiException e) {
077 e.printStackTrace();
078 }
079 String body = response.getBody();
080 JSONObject obj = JSON.parseObject(body);
081 String shop_get_response = obj.get(“shop_get_response”) + “”;
082 JSONObject obj2 = JSON.parseObject(shop_get_response);
083 String shop = obj2.get(“shop”) + “”;
084 JSONObject obj3 = JSON.parseObject(shop);
085 String title = obj3.get(“pic_path”) + “”;
086 System.out.println(title);
087 }
088
089 /*
090 * 获取指定用户所有宝贝
091 /
092 public static void getItems() {
093 TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
094 TaobaokeItemsGetRequest req = new TaobaokeItemsGetRequest();
095 req.setNick(“terryang”);
096 req.setCid(0l);
097 req.setFields(“num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume”);
098 TaobaokeItemsGetResponse response = null;
099 try {
100 response = client.execute(req);
101 } catch (ApiException e) {
102 e.printStackTrace();
103 }
104 }
105
106 /*
107 * 获取宝贝详情
108 *
109 * @see 返回参数说明
110 * http://api.taobao.com/apidoc/dataStruct.htm?path=cid:4-dataStructId
111 * :63 -apiId:20-invokePath:item
112 */
113 public static void getItem() {
114 TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
115 ItemGetRequest req = new ItemGetRequest();
116 req.setFields(“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”);
117 req.setNumIid(1500008334147L);
118 ItemGetResponse response = null;
119 try {
120 response = client.execute(req, null);
121 } catch (ApiException e) {
122 e.printStackTrace();
123 }
124 }
125 }