淘宝/天猫的“拍立淘”功能是一种按图搜索淘宝商品的工具,它允许用户通过上传图片来搜索相似的商品。目前,淘宝/天猫的拍立淘功能主要是为移动端的用户提供的,并没有直接开放给开发者使用的API接口。
接口名称:item_search_img-按图搜索淘宝商品(拍立淘)
接口简介:通过upload_img上传图片至淘宝,获取url,将url请求参数传入拍立淘接口,可以搜索到相关商品。
测试入口:登录 - 跨境电商平台接口提供商 数据采集公司 数据接口定制服务 企业级数据服务商
公共参数:
名称 | 类型 | 必须 | 描述 |
---|---|---|---|
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版本 |
请求参数
请求参数:imgid=http://g-search3.alicdn.com/img/bao/uploaded/i4/O1CN01IDpcD81zHbpHs1YgT_!!2200811456689.jpg&cat=&page=1
参数说明:imgid:图片地址(支持淘宝或天猫图片地址,外部地址先调用上传图片(upload_img)接口,返回图片地址)
如:https://img.alicdn.com/imgextra/i3/15353738/TB2HDHAqN9YBuNjy0FfXXXIsVXa_!!15353738-0-beehive-scenes.jpg
page:页数
响应参数
Version: Date:
名称 | 类型 | 必须 | 示例值 | 描述 |
---|---|---|---|---|
title | String | 0 | 亲子装短袖t恤社会人衣服全家装一家三口母子母女纯棉夏装上衣潮 | 宝贝标题 |
cid | Int | 0 | 50015374 | |
list_type | String | 0 | 外观相似宝贝 | 列表类型 |
pic_url | String | 0 | //g-search3.alicdn.com/img/bao/uploaded/i4/TB26ry1rBsmBKNjSZFsXXaXSVXa_!!2628705716.jpg | 宝贝图片 |
promotion_price | String | 0 | 38.71 | 优惠价 |
price | Float | 0 | 39.50 | 价格 |
sales | Int | 0 | 7 | 销量 |
num_iid | Bigint | 0 | 575727312808 | 宝贝ID |
sample_id | Bigint | 0 | 1627115368 | 商品风格标识ID |
seller_nick | String | 0 | 专属味道之dzw | 掌柜昵称 |
is_tmall | Bool | 0 | false | |
post_fee | String | 0 | 0.00 | 物流费用 |
area | String | 0 | 广东 东莞 | 店铺所在地 |
detail_url | String | 0 | //item.taobao.com/item.htm?id=575727312808&ns=1#detail | 宝贝链接 |
java:
- 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-服务器.cn/taobao/item_search_img/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&imgid=http://g-search3.alicdn.com/img/bao/uploaded/i4/O1CN01IDpcD81zHbpHs1YgT_!!2200811456689.jpg&cat=";
- JSONObject json = getRequestFromUrl(url);
- System.out.println(json.toString());
- }
-
- }
- PHP:
-
- <?php
-
- // 请求示例 url 默认请求参数已经URL编码处理
- // 本示例代码未加密secret参数明文传输,若要加密请参考:https://open.onebound.cn/help/demo/sdk/demo-sign.php
- $method = "GET";
- $url = "https://api-服务器.cn/taobao/item_search_img/?key=<您自己的apiKey>&secret=<您自己的apiSecret>&imgid=http://g-search3.alicdn.com/img/bao/uploaded/i4/O1CN01IDpcD81zHbpHs1YgT_!!2200811456689.jpg&cat=";
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,FALSE);
- curl_setopt($curl, CURLOPT_FAILONERROR, false);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, true);
- curl_setopt($curl, CURLOPT_ENCODING, "gzip");
- var_dump(curl_exec($curl));
- ?>
如果您想在您的应用或网站中实现类似的功能,您可能需要考虑以下几种方法:
-
使用淘宝/天猫的移动端SDK:
淘宝/天猫可能为其移动应用提供了SDK(软件开发工具包),这些SDK可能包含了一些与拍立淘相关的功能。您可以查看淘宝/天猫的开放平台或开发者文档,了解是否有相关的SDK可供使用。 -
调用淘宝/天猫的搜索API并结合图像识别技术:
虽然淘宝/天猫没有直接提供按图搜索的API接口,但您可以尝试结合使用淘宝/天猫的商品搜索API和图像识别技术来实现类似的功能。首先,您可以使用图像识别技术从上传的图片中提取关键特征或标签;然后,您可以根据这些特征或标签调用淘宝/天猫的商品搜索API来搜索相关的商品。需要注意的是,这种方法可能无法完全达到拍立淘的精确度和效果,因为图像识别技术可能无法准确提取出所有与商品相关的特征,而且淘宝/天猫的商品搜索API也可能无法完全匹配这些特征。
-
与第三方服务商合作:
有些第三方服务商可能提供了按图搜索商品的服务,并且可能已经集成了淘宝/天猫的商品数据。您可以考虑与这些服务商合作,使用他们提供的API接口来实现按图搜索淘宝商品的功能。
无论您选择哪种方法,都需要确保遵守淘宝/天猫平台的使用条款和规定,不要进行任何违规操作。同时,也要注意保护用户的隐私和数据安全。
如果您在开发过程中遇到任何问题或需要进一步的帮助,建议直接联系淘宝/天猫的开放平台技术支持团队或访问相关的开发者社区和论坛。