?
??一、接口基礎(chǔ)
速賣通開放平臺(tái)提供/api/products/search接口,支持通過關(guān)鍵詞獲取商品列表。主要參數(shù)包括:
keywords:搜索關(guān)鍵詞(需URL編碼)
categoryId:類目篩選
minPrice/maxPrice:價(jià)格區(qū)間
sort:排序方式(默認(rèn)"sale_num_desc")
?
二、Python調(diào)用示例
import requests
import urllib.parse
def search_aliexpress(keyword):
API_URL = "https://api.aliexpress.com/api/products/search"
APP_KEY = "your_app_key" # 替換為實(shí)際值
params = {
"keywords": urllib.parse.quote(keyword),
"sort": "sale_num_desc",
"pageSize": 50,
"app_key": APP_KEY
}
try:
response = requests.get(API_URL, params=params)
response.raise_for_status()
return response.json()["result"]["products"]
except Exception as e:
print(f"API調(diào)用失敗: {str(e)}")
return []
# 調(diào)用示例
products = search_aliexpress("wireless earphone")
for product in products[:3]:
print(f"{product['title']} - ${product['price']}")
三、關(guān)鍵技術(shù)要點(diǎn)
簽名認(rèn)證:需按文檔生成sign參數(shù)(示例代碼省略)
分頁(yè)處理:通過pageNo參數(shù)實(shí)現(xiàn),建議單頁(yè)不超過100條
錯(cuò)誤處理:特別注意code=1006表示關(guān)鍵詞違規(guī)
性能優(yōu)化:
使用本地緩存高頻關(guān)鍵詞結(jié)果
設(shè)置請(qǐng)求超時(shí)(建議5-10秒)
異步請(qǐng)求多個(gè)關(guān)鍵詞時(shí)控制并發(fā)量
四、返回?cái)?shù)據(jù)結(jié)構(gòu)
典型響應(yīng)字段:
{
"productId": "123456",
"title": "Wireless Bluetooth Earphone",
"price": 15.99,
"soldCnt": 5000,
"storeName": "XYZ Store",
"imageUrl": "..."
}
五、注意事項(xiàng)
需提前申請(qǐng)開發(fā)者賬號(hào)并創(chuàng)建應(yīng)用
免費(fèi)版API有QPS限制(通常5次/秒)
敏感詞(如品牌名)可能被過濾
建議使用海外服務(wù)器調(diào)用避免地域限制?