亚马逊SP-API开发实战:商品数据获取与操作

一、API接入准备

开发者注册:

登录亚马逊开发者中心申请SP-API权限

完成MWS迁移(如适用)

认证配置:

# OAuth2.0认证示例
import requests
auth_url = "https://api.amazon.com/auth/o2/token"
params = {
    "grant_type": "refresh_token",
    "refresh_token": "YOUR_REFRESH_TOKEN",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET"
}
response = requests.post(auth_url, data=params)
access_token = response.json()['access_token']

亚马逊SP-API开发实战:商品数据获取与操作_第1张图片

点击获取key和secret

二、核心商品接口

1. 商品信息查询(GetCatalogItem)

headers = {
    "x-amz-access-token": access_token,
    "Content-Type": "application/json"
}
item_api = "https://sellingpartnerapi-na.amazon.com/catalog/v0/items/ASIN12345"
response = requests.get(item_api, headers=headers)
print(response.json())

返回字段包含:

ASIN

商品标题

主图URL

价格信息

库存状态

2. 批量查询接口(ListCatalogItems)

支持分页查询,每次最多返回1000条记录

三、注意事项

限流规则:每秒1请求(可申请提升)

数据缓存:建议本地缓存高频访问数据

错误处理:

if response.status_code == 429:
    retry_after = int(response.headers['Retry-After'])
    time.sleep(retry_after)

四、最佳实践

使用AWS Lambda处理异步请求

结合Amazon SQS实现消息队列

定期同步商品数据到本地数据库

你可能感兴趣的:(商品详情,接口,亚马逊,oracle,数据库)