京东商品评论 API(JSON 数据返回)核心解析
前言
一、接口核心功能
京东商品评论 API 允许开发者通过 HTTP 请求获取指定商品的评论数据,支持以下核心功能:
- 多维数据获取:
- 评论内容:文字、图片、视频(部分接口支持)。
- 用户评分:1-5 星,支持按评分筛选(如仅获取好评/差评)。
- 时间信息:评论时间戳、自定义时间范围筛选(如最近 30 天)。
- 用户属性:用户昵称(脱敏处理)、用户等级(如钻石会员)、所在地区(脱敏)。
- 商家回复:商家对评论的回复内容。
- 评论类型:首评、追评、晒单评论。
- 结构化标签:如“物流快”“质量好”等标签统计。
- 排序与筛选:
- 评分筛选:按好评(4-5 星)、中评(3 星)、差评(1-2 星)分类。
- 时间排序:按评论时间降序或升序排列。
- 推荐排序:基于京东算法推荐热门评论。
- 有用投票数:按用户对评论的点赞数排序。
- 分页与批量获取:
- 分页参数:支持
page
(页码)和pageSize
(每页数量,最大 100 条)。 - 循环获取:通过判断返回评论数是否等于
pageSize
,决定是否继续请求下一页。
- 分页参数:支持
二、请求构造
- 基础参数:
{
"method": "jingdong.ware.productcomment.get",
"app_key": "YOUR_APP_KEY",
"timestamp": "20250908153000",
"format": "json",
"v": "2.0",
"sign_method": "md5"
}
- 业务参数:
{
"skuId": "100012345678", // 商品 SKU ID
"page": 1, // 页码(从 1 开始)
"pageSize": 10, // 每页数量(最大 100)
"score": 0, // 评分筛选(0=全部,1=差评,2=中评,3=好评)
"sortType": 5 // 排序方式(5=推荐排序,6=时间排序)
}
- 签名生成:
- 使用
AppSecret
对所有参数按字典序排序后加密(MD5),确保请求合法性。 - Python 示例:
import hashlib
def generate_sign(params, app_secret):
sorted_params = sorted(params.items())
sign_str = app_secret + ''.join(f"{k}{v}" for k, v in sorted_params) + app_secret
return hashlib.md5(sign_str.encode()).hexdigest().upper()
- 使用
三、JSON 数据返回示例
- 商品评论列表接口:
- 请求地址:
https://club.jd.com/comment/productPageComments.action
- 请求方式:GET
- 返回结构:
{
"code": 200,
"message": "success",
"data": {
"productCommentSummary": {
"goodRateShow": 98, // 好评率(%)
"commentCount": 50000, // 总评论数
"goodCount": 48000, // 好评数
"generalCount": 1500, // 中评数
"poorCount": 500 // 差评数
},
"hotCommentTagStatistics": [ // 热门标签
{ "id": 1, "name": "物流快", "count": 5000 },
{ "id": 2, "name": "质量好", "count": 3000 }
],
"comments": [ // 评论列表
{
"id": 123456789,
"content": "东西很好,物流很快",
"creationTime": "2023-01-01 12:00:00",
"score": 5,
"usefulVoteCount": 200, // 有用投票数
"nickname": "jd_123", // 用户昵称(脱敏)
"productColor": "白色",
"productSize": "XL",
"images": [ // 评论图片
{ "id": 111, "imgUrl": "//img30.360buyimg.com/n1/s450x450_jfs/..." }
],
"afterUserComment": { // 追评
"content": "使用后效果很好,推荐购买!",
"creationTime": "2023-01-10 10:00:00"
}
}
]
}
}
- 请求地址:
- 商品评价统计接口:
- 请求地址:
https://club.jd.com/comment/productCommentSummaries.action
- 请求方式:GET
- 返回结构:
{
"CommentsCount": [
{
"SkuId": 100012014970,
"ProductId": 100012014970,
"CommentCount": 50000, // 总评论数
"GoodCount": 48000, // 好评数
"GeneralCount": 1500, // 中评数
"PoorCount": 500, // 差评数
"VideoCount": 200, // 视频评论数
"AfterCount": 300, // 追评数
"GoodRate": 0.98, // 好评率
"GeneralRate": 0.03, // 中评率
"PoorRate": 0.01 // 差评率
}
]
}
- 请求地址:
四、关键字段说明
字段 | 说明 |
---|---|
skuId | 商品唯一标识符,用于定位具体商品或 SKU(如不同颜色、尺寸的变体)。 |
commentCount | 商品总评论数。 |
goodRateShow | 好评率(%)。 |
comments.content | 评论内容(可能包含 HTML 标签,需清洗)。 |
comments.score | 用户评分(1-5 星)。 |
comments.creationTime | 评论时间戳。 |
comments.images | 评论图片 URL 列表(部分评论可能无图片)。 |
hotCommentTagStatistics | 热门标签统计,如“物流快”“质量好”的标签数量。 |
五、应用场景与代码示例
- 评论情感分析:
- 目标:统计好评、差评关键词,分析用户关注焦点。
- 方法:使用 Python 的
jieba
分词 +TextBlob
或自定义情感词典。 - 示例:
from collections import Counter
import jieba
comments = [comment["content"] for comment in data["data"]["comments"]]
words = [word for comment in comments for word in jieba.cut(comment)]
keyword_counts = Counter([word for word in words if len(word) > 1])
print(keyword_counts.most_common(10)) # 输出高频词
- 分页获取全部评论:
- 目标:获取某商品的全部评论(如手机、家电等高评论量商品)。
- 方法:通过循环请求分页数据,直到返回评论数小于
pageSize
。 - 示例:
import requests
import time
def get_all_comments(sku_id, page_size=50):
all_comments = []
page = 1
while True:
params = {
"skuId": sku_id,
"page": page,
"pageSize": page_size,
"accessToken": "YOUR_TOKEN"
}
response = requests.get("https://api.jd.com/comment", params=params)
data = response.json()
all_comments.extend(data["data"]["comments"])
if len(data["data"]["comments"]) < page_size:
break
page += 1
time.sleep(1) # 避免频率过高
return all_comments
- 按评分筛选评论:
- 目标:仅获取差评(1-2 星)进行分析。
- 方法:在请求参数中设置
score=1
。