一、接口概述
拍立淘是義烏購平臺提供的以圖搜貨服務,通過HTTP RESTful API實現。當前版本為v3.2,支持JPG/PNG格式圖片(≤5MB),返回相似商品列表及供應鏈信息。
二、接入準備
-
申請開發者賬號
# 開發者注冊示例(偽代碼)
import requests
auth_url = "https://open.yiwugo.com/oauth2/token"
params = {"client_id": "your_app_key","client_secret": "your_app_secret","grant_type": "client_credentials"
}
response = requests.post(auth_url, data=params)
access_token = response.json()["access_token"]
三、核心接口調用
1. 圖片上傳接口
def image_search(image_path, token):url = "https://api.yiwugo.com/v3/image/search"headers = {"Authorization": f"Bearer {token}"}with open(image_path, 'rb') as f:files = {'image': (image_path.split('/')[-1], f, 'image/jpeg')}response = requests.post(url, files=files, headers=headers)if response.status_code == 200:return response.json()["data"]["items"]else:raise Exception(f"API Error: {response.text}")# 調用示例
results = image_search("product.jpg", access_token)
2. 響應數據結構
{"code": 200,"data": {"items": [{"product_id": "P123456","similarity": 0.92,"price_range": [2.5, 3.8],"main_image": "https://img.yiwugo.com/...","supplier_info": {"company_id": "C7890","gold_supplier": true}}]}
}
四、最佳實踐
-
圖片預處理建議:
-
分辨率建議800x800像素
-
使用白色背景商品圖
-
避免水印和拼接圖
-
-
錯誤處理:
try:results = image_search("demo.jpg", token)
except Exception as e:print(f"搜索失敗:{str(e)}")# 建議重試機制:間隔2秒重試3次
五、QPS限制
基礎版:1次/秒 企業版:10次/秒(需簽約)