首页>代码>java调用第三方淘宝api接口实例代码>/taobao/src/com/taobao/api/APITest.java
package com.taobao.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.taobao.api.request.ItemGetRequest;
import com.taobao.api.request.ItemcatsGetRequest;
import com.taobao.api.request.ShopGetRequest;
import com.taobao.api.request.TaobaokeItemsGetRequest;
import com.taobao.api.response.ItemGetResponse;
import com.taobao.api.response.ItemcatsGetResponse;
import com.taobao.api.response.ShopGetResponse;
import com.taobao.api.response.TaobaokeItemsGetResponse;

public class APITest {
	protected static String url = "http://gw.api.taobao.com/router/rest";// 沙箱环境调用地址
	// 正式环境需要设置为:http://gw.api.taobao.com/router/rest
	// http://gw.api.tbsandbox.com/router/rest
	protected static String appkey = "你的key";
	protected static String appSecret = "你的secret";

	public static void main(String[] args) {
		// APITest.testItemGet();
		// getShopInfo();
		getItems();
		// getItem();
	}

	/**
	 * 获取所有类别目录
	 */
	public static void testItemGet() {
		TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
		ItemcatsGetRequest req = new ItemcatsGetRequest();
		req.setFields("cid,parent_cid,name,is_parent");
		req.setParentCid(0L);
		// req.setCids("18957,19562,");
		ItemcatsGetResponse response = null;
		try {
			response = client.execute(req);
		} catch (ApiException e) {
			e.printStackTrace();
		}
	}

	/**
	 * sid 店铺编号。shop+sid.taobao.com即店铺地址,如shop123456.taobao.com
	 * 
	 * @param cid
	 *            123456 店铺所属的类目编号
	 * @param nick
	 *            卖家昵称
	 * @param title
	 *            店铺标题
	 * @param desc
	 *            店铺描述
	 * @param bulletin
	 *            店铺公告
	 * @param pic_path
	 *            店标地址。返回相对路径,可以用"http://logo.taobao.com/shop-logo"来拼接成绝对路径
	 * @param created
	 *            开店时间。格式:yyyy-MM-dd HH:mm:ss
	 * @param modified
	 *            最后修改时间。格式:yyyy-MM-dd HH:mm:ss
	 * @param shop_score
	 *            店铺动态评分信息(item_score:商品描述评分;service_score:服务态度评分;delivery_score
	 *            :发货速度评分;)
	 */
	public static void getShopInfo() {
		TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
		ShopGetRequest req = new ShopGetRequest();
		req.setFields("shop_score,sid,cid,title,nick,desc,bulletin,pic_path,created,modified");
		req.setNick("hemp619");
		ShopGetResponse response = null;
		try {
			response = client.execute(req);
		} catch (ApiException e) {
			e.printStackTrace();
		}
		String body = response.getBody();
		JSONObject obj = JSON.parseObject(body);
		String shop_get_response = obj.get("shop_get_response") + "";
		JSONObject obj2 = JSON.parseObject(shop_get_response);
		String shop = obj2.get("shop") + "";
		JSONObject obj3 = JSON.parseObject(shop);
		String title = obj3.get("pic_path") + "";
		System.out.println(title);
	}

	/**
	 * 获取指定用户所有宝贝
	 */
	public static void getItems() {
		TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
		TaobaokeItemsGetRequest req = new TaobaokeItemsGetRequest();
		req.setNick("terryang");
		req.setCid(0l);
		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");
		TaobaokeItemsGetResponse response = null;
		try {
			response = client.execute(req);
		} catch (ApiException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取宝贝详情
	 * 
	 * @see 返回参数说明 
	 *      http://api.taobao.com/apidoc/dataStruct.htm?path=cid:4-dataStructId
	 *      :63 -apiId:20-invokePath:item
	 */
	public static void getItem() {
		TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
		ItemGetRequest req = new ItemGetRequest();
		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");
		req.setNumIid(1500008334147L);
		ItemGetResponse response = null;
		try {
			response = client.execute(req, null);
		} catch (ApiException e) {
			e.printStackTrace();
		}
	}
}
最近下载更多
13332222  LV1 2023年4月3日
lhchun  LV2 2023年2月22日
admin3366998855  LV2 2022年3月23日
zhubeihongbenny  LV4 2022年3月5日
781681653  LV1 2022年2月15日
刘亦菲9527  LV15 2021年12月27日
awen123  LV2 2021年10月10日
lichang714  LV2 2021年10月8日
十一不是一一  LV1 2021年10月6日
小桃子  LV12 2021年9月23日
最近浏览更多
xianyu091012  LV2 2023年7月19日
13332222  LV1 2023年4月3日
zch611  LV1 2023年2月26日
lhchun  LV2 2023年2月22日
yyy233  LV1 2022年12月17日
riso阿初  LV1 2022年11月7日
liweiyishuo  LV3 2022年8月1日
是你爸爸啊100  LV5 2022年7月23日
crosa_Don  LV18 2022年6月14日
18568642603 2022年5月21日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友