电子说
1. 核心请求参数
表格
| 参数 | 说明 | 必填 |
|---|---|---|
| note_id | 笔记 ID(URL / 分享链接提取) | 是 |
| access_token | 授权令牌 | 是 |
| app_key | 应用标识 | 是 |
| timestamp | 秒级时间戳 | 是 |
| sign | MD5 签名(参数排序 + App Secret) | 是 |
| fields | 自定义返回字段(如 title,content,images) | 否 |
二、作业笔记详情完整字段(JSON)
json
{
"code": 0,
"data": {
// 基础信息
"note_id": "66d3b9a...",
"title": "高数作业答案+解题步骤",
"content": "本次高数作业涵盖极限、导数...(含富文本)",
"note_type": "normal", // normal=图文/video=视频
"publish_time": "2026-05-07T16:30:00Z",
"status": "published", // published/draft/deleted
"is_commercial": false,
// 作业标签(关键)
"tags": ["高数作业", "大学数学", "解题技巧", "作业分享"],
"category": "education",
// 多媒体(作业图片/视频)
"images": [
"https://xxx.com/1.jpg", // 作业图1
"https://xxx.com/2.jpg" // 作业图2(最多9张)
],
"video": { // 视频笔记才有
"url": "https://xxx.com/video.mp4",
"cover": "https://xxx.com/cover.jpg",
"duration": 120 // 秒
},
// 互动数据
"interact": {
"like_count": 1280,
"collect_count": 342,
"comment_count": 89,
"share_count": 56
},
// 作者信息
"user": {
"user_id": "user_123",
"nickname": "学习小助手",
"avatar": "https://xxx.com/avatar.jpg",
"is_verified": false,
"follower_count": 5200
},
// 扩展(可选)
"location": "北京",
"product_info": null // 无商品则为空
}
}
三、作业笔记特征(筛选识别)
标题关键词:作业、答案、解题、步骤、错题、真题、复习
标签特征:含 #作业 #学科名+作业 #学习打卡 等
内容结构:题目→解答→步骤→答案→总结
多媒体:多张手写 / 打印作业图片,或视频讲解
四、Python 调用示例(v4)
python
运行
import requests
import hashlib
import time
def get_homework_note_detail(note_id, app_key, app_secret, access_token):
url = f"https://api.xiaohongshu.com/v4/notes/{note_id}"
ts = str(int(time.time()))
# 签名生成(ASCII升序)
sign_str = f"app_key{app_key}note_id{note_id}timestamp{ts}{app_secret}"
sign = hashlib.md5(sign_str.encode()).hexdigest()
params = {
"access_token": access_token,
"app_key": app_key,
"timestamp": ts,
"sign": sign,
"fields": "title,content,tags,images,interact,user"
}
resp = requests.get(url, params=params)
return resp.json() if resp.status_code == 200 else None
五、常见错误与处理
401:access_token 过期 → 用 refresh_token 刷新
403:权限不足 → 开放平台申请 “笔记详情” 权限
404:笔记不存在 / 私密 → 核对 note_id,确认笔记公开
429:频率超限 → 降频 + 缓存,或申请提额
审核编辑 黄宇
全部0条评论
快来发表一下你的评论吧 !