在淘宝和天猫这两个国内领先的电商平台上,商品描述是卖家向消费者展示商品详情的重要工具。为了方便第三方开发者或商家能够获取商品描述信息,淘宝/天猫提供了相应的API接口。本文将对一个假设的API接口taobao.item_get_desc进行返回值解读,以帮助开发者更好地理解和使用该接口。
一、接口概述
[taobao.item_get_desc](url)接口主要用于获取淘宝/天猫平台上的商品描述信息。通过传入商品ID等参数,接口将返回包含商品描述的JSON格式数据。这些数据可以帮助开发者在自己的应用或系统中展示商品详情,提升用户体验。
二、返回值结构
taobao.item_get_desc接口的返回值通常是一个JSON对象,包含了多个字段。下面是一个典型的返回值结构示例:
json复制代码
{
"request_id": "XXXXXXXXXXX", // 请求的唯一标识符,用于跟踪和调试
"item": {
"num_iid": "1234567890", // 商品ID,与传入参数一致
"title": "商品标题", // 商品标题信息
"price": "199.00", // 商品价格,可能包含货币单位等信息
"desc": "<p>这里是商品描述的内容...</p>", // 商品描述信息,通常为HTML格式
"desc_images": [ // 商品描述图片列表
{
"url": "https://img.example.com/desc_image1.jpg",
"position": 1
},
{
"url": "https://img.example.com/desc_image2.jpg",
"position": 2
},
// ...更多图片信息
],
"detail_url": "https://item.taobao.com/item.htm?id=1234567890", // 商品详情页链接
"other_fields": "其他可能存在的字段信息..." // 其他与商品相关的字段,根据接口版本和平台策略可能有所不同
},
"error_response": null // 错误信息,如果请求成功,则此字段为null
}
三、返回值字段详解
-
request_id:请求的唯一标识符。在调用接口时,系统会为每个请求生成一个唯一的ID,用于跟踪和调试。开发者可以在出现问题时提供此ID给技术支持人员,以便快速定位问题。
-
item:包含商品信息的对象。
- num_iid:商品ID,与传入参数一致。确保返回的数据与请求的商品相对应。
- title:商品标题信息。开发者可以将此字段展示在商品列表或详情页中。
- price:商品价格。可能包含货币单位等信息,开发者需要根据实际需要进行解析和展示。
- desc:商品描述信息。通常为HTML格式,包含了商品的详细介绍、功能特点、使用方法等。开发者需要确保自己的应用或系统能够正确解析和渲染HTML内容,以便用户能够清晰地查看商品描述。
- desc_images:商品描述图片列表。包含了商品描述中使用的图片的URL和位置信息。开发者可以将这些图片展示在商品详情页中,增强用户的购物体验。
- detail_url:商品详情页链接。这是一个指向淘宝/天猫平台商品详情页的URL,用户点击后可以查看更多关于商品的信息。
- other_fields:其他可能存在的字段信息。这些字段根据接口版本和平台策略可能有所不同,开发者需要查阅相关文档以了解具体含义和使用方法。
-
error_response:错误信息。如果请求失败或出现问题,此字段将包含错误代码和描述信息。开发者需要根据错误信息进行相应的处理,如重试请求、提示用户等。
四、使用建议
- 确保接口安全性:在调用淘宝/天猫的API接口时,需要注意接口的安全性。建议使用HTTPS协议进行通信,确保数据传输的加密和安全性。同时,不要将API密钥或敏感信息暴露在前端代码中,以免被恶意攻击者利用。
- 合理处理返回值:在接收API接口的返回值时,需要合理处理各种情况。首先,要检查返回值中是否存在
error_response字段,并根据错误信息进行相应的处理。其次,要正确解析和展示商品信息,确保用户能够清晰地查看商品描述和图片等内容。 - 遵守平台规则:在使用淘宝/天猫的API接口时,需要遵守平台的规则和政策。不要滥用接口或进行非法操作,以免被封禁或追究法律责任。
taobao.item_get_desc
请求地址:
| 名称 | 类型 | 必须 | 描述 |
|---|---|---|---|
| key | String | 是 | 调用key(必须以GET方式拼接在URL中) |
| secret | String | 是 | 调用密钥 |
| api_name | String | 是 | API接口名称(包括在请求地址中)[item_search,item_get,item_search_shop等] |
| cache | String | 否 | [yes,no]默认yes,将调用缓存的数据,速度比较快 |
| result_type | String | 否 | [json,jsonu,xml,serialize,var_export]返回数据格式,默认为json,jsonu输出的内容中文可以直接阅读 |
| lang | String | 否 | [cn,en,ru]翻译语言,默认cn简体中文 |
| version | String | 否 | API版本 |
请求参数:num_iid=520813250866
参数说明:num_iid:淘宝商品ID
Version: Date:
| 名称 | 类型 | 必须 | 示例值 | 描述 |
|---|---|---|---|---|
| item | item[] | 0 | 获得淘宝商品描述 |
- Curl
- PHP
- PHPsdk
- JAVA
- C#
- Python
- Golang
- javascript
- JS-SDK
- Ruby
- Swift
- Objective-C
- C
- C++
- Node.JS
- Kotlin
- Rust
- R
- MATLAB
复制
-- 请求示例 url 默认请求参数已经URL编码处理
curl -i "https://api-gw.onebound.cn/taobao/item_get_desc/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&num_iid=520813250866"
复制
{
"item": {
"desc": "\n <img src="http://img.alicdn.com/imgextra/i3/2200639983103/O1CN01B8rO8q1YnDpqtaSHZ_!!2200639983103-1-scmitem6000.gif" usemap="#IUSGU" />\n <map name="IUSGU"><area shape="rect" coords="6,10,786,541" href="https://pages.tmall.com/wow/an/cs/act/wupr?wh_biz=tm&wh_pid=3320144%2F17c73fe7b21&disableNav=YES&brandId=3320144&chaoshi_brand_waitou=true"></area><area shape="rect" coords="9,561,169,731" href="https://pages.tmall.com/wow/ark-pub/common/ee30c50a/tpl?wh_sid=a4a7a974fcf99970&mcBrandCard=true"></area><area shape="rect" coords="211,561,371,721" href="https://pages.tmall.com/wow/ark-pub/common/ee30c50a/tpl?wh_sid=b1f371c6cada937b&mcBrandCard=true"></area><area shape="rect" coords="415,562,575,722" href="https://pages.tmall.com/wow/ark-pub/common/ee30c50a/tpl?wh_sid=8fff1d96108c25a3&mcBrandCard=true"></area><area shape="rect" coords="597,563,757,723" href="https://pages.tmall.com/wow/ark-pub/common/ee30c50a/tpl?wh_sid=a4d5dbb8fee520eb&mcBrandCard=true"></area></map> \n <img src="http://img.alicdn.com/imgextra/i3/2200639983103/O1CN01MdspcQ1YnDpofKaYI_!!2200639983103-1-scmitem6000.gif" usemap="#EMBND" />\n <map name="EMBND"><area shape="rect" coords="3,253,355,792" href="https://chaoshi.detail.tmall.com/item.htm?id=627358747270&skuId=4958439969412"></area></map> \n <p> </p> \n <p> </p> \n <p> </p> \n <p> </p> \n <p> </p> \n <p> </p> \n <p> <img src="http://img.alicdn.com/imgextra/i4/2200639983103/O1CN01K5mRzF1YnDhfbLqYO_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /></p> \n <p> </p> \n <p><map name="GPSIJ"><area shape="rect" coords="194,8,374,148" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=536597702698"></area><area shape="rect" coords="377,10,557,148" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=611943282371"></area><area shape="rect" coords="564,15,742,150" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=613199006000"></area><area shape="rect" coords="197,165,372,299" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=602723508607"></area><area shape="rect" coords="382,170,554,305" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=44107699067"></area><area shape="rect" coords="567,165,739,305" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=44187888589"></area><area shape="rect" coords="197,318,374,455" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=533938505960"></area><area shape="rect" coords="386,318,558,453" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=591828039537"></area><area shape="rect" coords="567,318,741,460" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=566408329269"></area><area shape="rect" coords="196,470,371,606" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=533971548851"></area><area shape="rect" coords="380,473,557,610" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=577183292025"></area><area shape="rect" coords="565,470,740,613" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=573075979265"></area><area shape="rect" coords="197,622,262,676" href=""></area><area shape="rect" coords="199,624,374,758" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=554419816039"></area><area shape="rect" coords="381,620,556,762" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=592956242653"></area><area shape="rect" coords="564,623,739,764" href="https://chaoshi.detail.tmall.com/item.htm?spm=a1z34w.13877023.0.0.626531a5VcC2US&id=604301910718"></area></map> </p> \n <p><a href="https://chaoshi.detail.tmall.com/item.htm?spm=a220o.7406545.0.0.32c7697bmJA9L1&id=590048908797" target="_blank"></a></p> \n <p><img src="http://img.alicdn.com/imgextra/i3/2200639983103/O1CN01UzEW4I1YnDhVdkEFJ_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /></p> \n <p> </p> \n <p><img src="http://img.alicdn.com/imgextra/i3/2200639983103/O1CN016eKqLt1YnDnXbDcWs_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /><img src="http://img.alicdn.com/imgextra/i2/2200639983103/O1CN01GDW3H61YnDnhPYxl7_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /><img align="absmiddle" src="http://img.alicdn.com/imgextra/i2/3596645218/O1CN01seMU6n1oPt9fOvcj4_!!3596645218-0-scmitem6000.jpg" /><img src="http://img.alicdn.com/imgextra/i2/2200639983103/O1CN0162Bmh21YnDnaPMaTM_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /><img align="absmiddle" src="http://img.alicdn.com/imgextra/i3/3596645218/O1CN01f4fzGM1oPt9XJ7Hk2_!!3596645218-0-scmitem6000.jpg" /><img align="absmiddle" src="http://img.alicdn.com/imgextra/i4/3596645218/O1CN01rWjGD61oPt9fgZiT4_!!3596645218-0-scmitem6000.jpg" /><img src="http://img.alicdn.com/imgextra/i2/2200639983103/O1CN01DfHuV61YnDjRoGnAQ_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /><img src="http://img.alicdn.com/imgextra/i3/2200639983103/O1CN01QZgCx01YnDjXm4Y03_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /><img align="absmiddle" src="http://img.alicdn.com/imgextra/i3/2142811280/O1CN01WxEC6x1LKHSoigkL0_!!2142811280-0-scmitem6000.jpg" /><img align="absmiddle" src="http://img.alicdn.com/imgextra/i2/2200639983103/O1CN01CzM2ro1YnDUFRy4lH_!!2200639983103-0-scmitem6000.jpg" /><img src="http://img.alicdn.com/imgextra/i3/2200639983103/O1CN01hy4eW41YnDnoTFBOb_!!2200639983103-0-scmitem6000.jpg" align="absmiddle" /></p> \n <p> </p> \n <p> </p>\n <script src="https://g.alicdn.com/i/popshop/0.0.23/p/seemore/load.js?c"></script> \n ",
"data_from": "app_vip"
},
"error": "",
"reason": "",
"error_code": "0000",
"cache": 0,
"api_info": "today:24 max:10000 all[39=24+0+15];expires:2030-12-31",
"execution_time": "0.666",
"server_time": "Beijing/2023-06-21 09:18:44",
"client_ip": "115.153.49.96",
"call_args": [],
"api_type": "taobao",
"translate_language": "zh-CN",
"translate_engine": "baidu",
"server_memory": "0.86MB",
"request_id": "gw-4.64924ff43c9b9",
"last_id": "1821985889"
}
复制
{
"error": "item-not-found",
"reason": "商品没找到",
"error_code": "2000",
"success": 0,
"cache": 0,
"api_info": "today:0 max:10000",
"execution_time": 0.081,
"server_time": "Beijing/2020-06-10 23:44:00",
"call_args": [],
"api_type": "taobao",
"request_id": "15ee0ffc041242"}
| 状态代码(error_code) | 状态信息 | 详细描述 | 是否收费 |
|---|---|---|---|
| 0000 | success | 接口调用成功并返回相关数据 | 是 |
| 2000 | Search success but no result | 接口访问成功,但是搜索没有结果 | 是 |
| 4000 | Server internal error | 服务器内部错误 | 否 |
| 4001 | Network error | 网络错误 | 否 |
| 4002 | Target server error | 目标服务器错误 | 否 |
| 4003 | Param error | 用户输入参数错误 | 忽略 |
| 4004 | Account not found | 用户帐号不存在 | 忽略 |
| 4005 | Invalid authentication credentials | 授权失败 | 忽略 |
| 4006 | API stopped | 您的当前API已停用 | 忽略 |
| 4007 | Account stopped | 您的账户已停用 | 忽略 |
| 4008 | API rate limit exceeded | 并发已达上限 | 忽略 |
| 4009 | API maintenance | API维护中 | 忽略 |
| 4010 | API not found with these values | API不存在 | 忽略 |
| 4012 | Please add api first | 请先添加api | 忽略 |
| 4013 | Number of calls exceeded | 调用次数超限 | 忽略 |
| 4014 | Missing url param | 参数缺失 | 忽略 |
| 4015 | Wrong pageToken | 参数pageToken有误 | 忽略 |
| 4016 | Insufficient balance | 余额不足 | 忽略 |
| 4017 | timeout error | 请求超时 | 否 |
| 5000 | unknown error | 未知错误 | 否 |