首页 > 大数据 > 数据挖掘 > 小红书笔记详情API接口调用详解
access_token(授权令牌)。请求头
json{"Authorization": "Bearer {access_token}","Content-Type": "application/json"}
必填参数
| 参数名 | 类型 | 说明 |
|---|---|---|
note_id |
String | 笔记唯一ID(如
649c46ab000000002702ad36) |
access_token |
String | 开放平台获取的授权令牌 |
可选参数
| 参数名 | 类型 | 说明 |
|---|---|---|
fields |
String | 指定返回字段(如
title,content,images) |
timestamp |
Int | 请求时间戳(防重放攻击) |
sign |
String | 加密签名(需按官方算法生成) |
json{"code": 200,"message": "success","data": {"note_id": "649c46ab000000002702ad36","title": "春季美妆新品推荐","content": "<p>今天分享几款超火的美妆新品...</p>","images": ["https://example.com/image1.jpg","https://example.com/image2.jpg"],"videos": [{"type": "video","url": "https://example.com/video.mp4","cover": "https://example.com/cover.jpg"}],"tags": ["美妆", "新品"],"like_count": 1024,"comment_count": 256,"favorite_count": 512,"share_count": 128,"author": {"user_id": "987654321","nickname": "美妆达人","avatar": "https://example.com/avatar.jpg","follower_count": 100000},"publish_time": "2025-04-25T14:30:00Z","location": {"name": "上海","latitude": 31.2304,"longitude": 121.4737}}}
常见错误码
| 错误码 | 说明 | 解决方案 |
|---|---|---|
| 401 | 无效的
access_token |
检查令牌是否过期或权限不足 |
| 404 | 笔记不存在或已删除 | 确认
note_id正确性 |
| 429 | 调用频率超限 | 优化代码减少请求,或申请提额 |
| 500 | 服务器内部错误 | 稍后重试并联系技术支持 |
排查步骤
access_token有效性及权限范围。note_id格式正确(通常为24位字母数字组合)。message字段获取具体错误原因。pythonimport requestsdef get_note_details(note_id, access_token):url = f"https://api.xiaohongshu.com/v1/notes/{note_id}"headers = {"Authorization": f"Bearer {access_token}","Content-Type": "application/json"}try:response = requests.get(url, headers=headers)response.raise_for_status()data = response.json()if data.get("code") == 200:return data["data"]else:print(f"API错误: {data.get('message')}")except requests.exceptions.RequestException as e:print(f"请求失败: {e}")# 使用示例note_id = "649c46ab000000002702ad36"access_token = "YOUR_ACCESS_TOKEN"details = get_note_details(note_id, access_token)if details:print(f"标题: {details['title']}")print(f"点赞数: {details['like_count']}")print(f"作者: {details['author']['nickname']}")
content字段可能包含HTML标签,需用
BeautifulSoup等库解析。Referer头)。page和
size)。tags字段可构建内容分类标签体系。如需更高级功能(如评论抓取),需联系小红书商务团队申请特殊权限。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70046834/viewspace-3089490/ ,如需转载,请注明出处,否则将追究法律责任。