一、接口认证流程
获取访问令牌
调用OAuth2.0认证接口获取access_token:
import requests
auth_url = "https://oauth.jd.com/oauth/token"
params = {
"client_id": "YOUR_APP_KEY",
"client_secret": "YOUR_SECRET",
"grant_type": "access_token",
"scope": "product_comment"
}
response = requests.post(auth_url, data=params)
access_token = response.json()['access_token']
二、核心API调用
商品评论接口路径:
https://api.jd.com/routerjson?method=jingdong.biz.product.comment.list.query
请求参数示例:
payload = {
"token": access_token,
"method": "jingdong.biz.product.comment.list.query",
"skuId": "100000000001", # 商品编号
"page": 1,
"pageSize": 10,
"type": "1" # 1=全部评论 2=好评 3=中评 4=差评
}
headers = {"Content-Type": "application/json"}
三、分页处理逻辑
响应数据结构包含关键字段:
{
"result": {
"comments": [
{
"content": "质量非常好",
"creationTime": "2023-05-20 14:30:00",
"score": 5
}
],
"total": 128 # 总评论数
}
}
分页计算示例:
total_comments = response['result']['total']
total_pages = (total_comments + pageSize - 1) // pageSize
四、数据解析技巧
时间戳转换
from datetime import datetime
comment_time = datetime.strptime(
comment['creationTime'],
'%Y-%m-%d %H:%M:%S'
)
评分分布统计
score_counts = {5:0, 4:0, 3:0, 2:0, 1:0}
for comment in comments:
score_counts[comment['score']] += 1
五、注意事项
频率限制:单账号每分钟不超过100次请求
字段说明:
score:评分(1-5分)
usefulVoteCount:点赞数
replyCount:回复数
实践提示:建议配合京东商品详情API(jingdong.biz.product.get)构建完整商品分析系统,通过skuId关联商品基础信息。