API接口获取商品详情数据

        API( Application Programming Interface ),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认API在Windows编程中的重要性.大多数的编程语言都支持API编程,而.Net平台中的MFC(Microsoft Foundation Class Library)构架本身就封装了大部分的API。

1、公共参数

请求地址: https://api-gw.onebound.cn/dangdang/item_get

名称类型必须描述
keyString调用key(必须以GET方式拼接在URL中)
secretString调用密钥
api_nameStringAPI接口名称(包括在请求地址中)[item_search,item_get,item_search_shop等]
cacheString[yes,no]默认yes,将调用缓存的数据,速度比较快
result_typeString[json,jsonu,xml,serialize,var_export]返回数据格式,默认为json,jsonu输出的内容中文可以直接阅读
langString[cn,en,ru]翻译语言,默认cn简体中文
versionStringAPI版本

2、请求参数

请求参数:num_iid=25122027

参数说明:num_iid:EBAY商品ID

3、响应参数

Version: Date:

名称类型必须示例值描述

num_iid

Bigint025122027宝贝ID

title

String0朗读者(1-3辑)(荣获2017年度大众喜爱的50种图书)宝贝标题

desc_short

String0商品简介

promotion_price

Float0156.00优惠价

price

Float0156.00价格

total_price

Float00

suggestive_price

Float00

orginal_price

Float0156.00原价

nick

String0当当自营掌柜昵称

num

Int0

min_num

Int00

detail_url

String0http://product.dangdang.com/25122027.html宝贝链接

pic_url

String0http://img3m7.ddimg.cn/84/26/25122027-1_w_7.jpg宝贝图片

brand

String0品牌名称

brandId

Int0品牌ID

rootCatId

Int0顶级分类ID

cid

Int0

favcount

Int00

fanscount

Int00

crumbs

Mix0

created_time

String0

modified_time

String0

delist_time

String0

desc

String0

item_imgs

Mix0[{ "url": "http://img3m7.ddimg.cn/84/26/25122027-1_w_7.jpg"}]商品图片

item_weight

String0

item_size

String0

location

String0发货地

express_fee

Float06.00快递费用

ems_fee

Float06.00EMS费用

post_fee

Float06.00物流费用

shipping_to

String0发货至

has_discount

Boolean0false

video

Mix0[{}]商品视频

is_virtual

String0

sample_id

String0商品风格标识ID

is_promotion

Boolean0false

props_name

String01627207:1347647754:颜色分类:长方形带开瓶器+送工具刀卡+链子;1627207:1347647753:颜色分类:椭圆形带开瓶器+送工具刀卡+链子;商品属性名

prop_imgs

Mix0{"prop_img": [ {"properties": "1627207:1347647754", "url": "//gd2.alicdn.com/imgextra/i3/2596264565/TB2.XeblVXXXXXkXpXXXXXXXXXX_!!2596264565.jpg"}]}商品属性图片列表

property_alias

String020509:9974422:36;1627207:28326:红色;20509:9975710:38;1627207:28326:红色;20509:9981357:40;1627207:28326:红色商品属性别名

props

Mix0[{ "name": "产地","value": "中国" }]商品详情

total_sold

Int0

skus

Mix0{"sku": [{"price": "39", "total_price": null, "orginal_price": "39.00", "properties": "1627207:1347647754", "properties_name": "1627207:1347647754:颜色分类:长方形带开瓶器+送工具刀卡+链子", "quantity": "305", "sku_id": "3166598625985"}]商品规格信息

seller_id

Int02844096782卖家ID

sales

Int0138销量

shop_id

Bigint0151372205店铺ID

props_list

Mix0{20509:9974422: 尺码:36}商品属性

seller_info

Mix0{"nick": "欢乐购客栈", "city": null, "level": 12, "bail": "2000", "rate": 96, "score": "4.8", "delivery_score": "4.8", "item_score": "4.8", "shop_type": null, "user_num_id": "2596264565", "sid": "127203758", "title": "欢乐购客栈", "zhuy": "//shop127203758.taobao.com", "company_name": null, "menu": [] }卖家信息

tmall

Boolean0false是否天猫

error

String0错误信息

warning

String0price_json error;skus miss;警告信息

url_log

Mix0[]

method

String0item_tmall:pget_item

promo_type

String0

props_img

Mix01627207:28326": "//img.alicdn.com/imgextra/i2/2844096782/O1CN01VrjpXt1zyCc9DvERE_!!2844096782.jpg属性图片

shop_item

Mix0[]

relate_items

Mix0[]

4、请求示例

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.PrintWriter;
import java.net.URLConnection;

public class Example {
	private static String readAll(Reader rd) throws IOException {
		StringBuilder sb = new StringBuilder();
		int cp;
		while ((cp = rd.read()) != -1) {
			sb.append((char) cp);
		}
		return  sb.toString();
	}
	public static JSONObject postRequestFromUrl(String url, String body) throws IOException, JSONException {
		URL realUrl = new URL(url);
		URLConnection conn = realUrl.openConnection();
		conn.setDoOutput(true);
		conn.setDoInput(true);
		PrintWriter out = new PrintWriter(conn.getOutputStream());
		out.print(body);
		out.flush();
		InputStream instream = conn.getInputStream();
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));
			String jsonText = readAll(rd);
			JSONObject json = new JSONObject(jsonText);
			return json;
		} finally {
			instream.close();
		}
	}
	public static JSONObject getRequestFromUrl(String url) throws IOException, JSONException {
		URL realUrl = new URL(url);
		URLConnection conn = realUrl.openConnection();
		InputStream instream = conn.getInputStream();
		try {
			BufferedReader rd = new BufferedReader(new InputStreamReader(instream, Charset.forName("UTF-8")));
			String jsonText = readAll(rd);
			JSONObject json = new JSONObject(jsonText);
			return json;
		} finally {
			instream.close();
		}
	}
	public static void main(String[] args) throws IOException, JSONException {
		// 请求示例 url 默认请求参数已经URL编码处理
		String url = "https://api-gw.onebound.cn/dangdang/item_get/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=25122027";
		JSONObject json = getRequestFromUrl(url);
		System.out.println(json.toString());
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值