XHS(小红书)使用指南
基于 TikHub OpenAPI(
https://api.tikhub.io)整理的小红书接口文档。
目录
通用说明
a. 调用策略:多系列搭配使用(重要)
小红书接口目前最稳定的是 App V2 系列。强烈建议所有用户采用"主系列 + 1~2 个备用系列"的搭配策略,将 2~3 个系列组合使用,提升整体业务可用性。
b. 调用优先级:App V2(推荐)> App V1(兜底)> Web V3(第三备选)
App V2 为主推荐系列,当前最稳定、数据最完整,建议作为首选;App V1 与 App V2 字段口径接近,适合作为第一备用兜底;Web V3 是面向企业用户开放的第三备选 Web 端通道,需要
xsec_token(可由分享链接抽取),但返回的数据维度比 App V2 / App V1 少,因此即便是企业用户也建议合理搭配多个系列一起使用,不要只用 Web V3;Web V2 / Web 系列只有小部分接口可用、稳定性也不一定有保障,不推荐作为主力,仅在前面三个系列都不满足需求时作为补充。
c. 一句话建议:不要只押注一个系列。生产环境推荐至少配置 2 个系列做主备搭配;企业用户使用 Web V3 时,请额外搭配 App V2 / App V1 来补足数据维度。
d. 返回字段提示:App 系列接口(App V2 / App V1)之间结构相似,字段命名基本可以互相对应;但 Web 系列接口(Web V3 / Web V2 / Web)返回的 JSON 结构各不相同,字段名、嵌套层级、数据维度都可能不一样,使用时请务必先查看每个接口的实际返回 JSON 字段,再做解析和映射。
1. 单一笔记
小红书的笔记分为两类:图文笔记(图片笔记) 和 视频笔记。App V2 系列为两种类型提供了独立的端点,数据最完整;Web V3 用同一个接口处理两种类型,由响应字段区分。
通用建议:优先使用 App V2 系列;企业用户在能拿到
xsec_token的场景下可搭配 Web V3 使用。
综合示例:三系列搭配获取单一笔记详情
下面给出一段示意代码,演示**主系列(App V2)→ 备用 1(App V1)→ 备用 2(Web V3)**的搭配调用思路,按照优先级依次尝试,前一个成功就直接返回,失败再降级到下一个。
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9NOTE_ID = "697c0eee000000000a03c308"
10XSEC_TOKEN = "ABxxxxxxxxxxxxxx" # Required for Web V3, extract from share link / Web V3 需要,可从分享链接抽取
11IS_VIDEO = False # Note type: True=video note, False=image note / 笔记类型:True=视频笔记,False=图文笔记
12
13
14# --- Primary: App V2 / 主系列:App V2 ---
15def fetch_by_app_v2(note_id: str, is_video: bool):
16 if is_video:
17 path = "/api/v1/xiaohongshu/app_v2/get_video_note_detail"
18 else:
19 path = "/api/v1/xiaohongshu/app_v2/get_image_note_detail"
20 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
21 params={"note_id": note_id})
22
23
24# --- Fallback 1: App V1 (image notes only; no video download URL, not recommended for videos) / 备用 1:App V1(仅图文有效,视频不含下载链接,不建议用于视频)---
25def fetch_by_app_v1(note_id: str):
26 path = "/api/v1/xiaohongshu/app/get_note_info"
27 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
28 params={"note_id": note_id})
29
30
31# --- Fallback 2: Web V3 (enterprise users only, requires xsec_token) / 备用 2:Web V3(企业用户专用,需要 xsec_token)---
32def fetch_by_web_v3(note_id: str, xsec_token: str):
33 path = "/api/v1/xiaohongshu/web_v3/fetch_note_detail"
34 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
35 params={"note_id": note_id, "xsec_token": xsec_token})
36
37
38# --- Try all three series in order / 三系列依次尝试 ---
39def get_note_detail(note_id: str, xsec_token: str, is_video: bool):
40 # 1) Primary: App V2 / 主系列:App V2
41 try:
42 r = fetch_by_app_v2(note_id, is_video)
43 if r.ok and r.json().get("code") == 200:
44 return {"source": "app_v2", "data": r.json()}
45 except Exception as e:
46 print("App V2 调用失败:", e)
47
48 # 2) Fallback 1: App V1 (skip this step for video notes) / 备用 1:App V1(视频笔记建议跳过此步)
49 if not is_video:
50 try:
51 r = fetch_by_app_v1(note_id)
52 if r.ok and r.json().get("code") == 200:
53 return {"source": "app_v1", "data": r.json()}
54 except Exception as e:
55 print("App V1 调用失败:", e)
56
57 # 3) Fallback 2: Web V3 / 备用 2:Web V3
58 try:
59 r = fetch_by_web_v3(note_id, xsec_token)
60 if r.ok and r.json().get("code") == 200:
61 return {"source": "web_v3", "data": r.json()}
62 except Exception as e:
63 print("Web V3 调用失败:", e)
64
65 return None
66
67
68result = get_note_detail(NOTE_ID, XSEC_TOKEN, IS_VIDEO)
69print(result)提示:上面的成功判断(
code == 200)是示意写法,实际请按各系列返回的 JSON 字段做判断;不同系列返回结构不一致,建议各系列分别写解析逻辑。
1.1 图片笔记(图文笔记)
1.1.1 [App V2] 获取图文笔记详情 ⭐ 推荐
获取图文笔记的完整详情数据(图片地址、标题、正文、标签、互动数据等)。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_image_note_detail - 官方文档:docs.tikhub.io/420136391e0
- 参数:
note_id(string, 可选):笔记 ID,例如"697c0eee000000000a03c308"share_text(string, 可选):小红书分享链接(支持 APP / Web 端)- 二选一,优先使用
note_id;都传则以note_id为准
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
5
6url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_image_note_detail"
7params = {
8 "note_id": "697c0eee000000000a03c308",
9 # "share_text": "https://www.xiaohongshu.com/discovery/item/...",
10}
11r = requests.get(url, headers=HEADERS, params=params)
12print(r.json())1.1.2 [App V1] 获取笔记信息 V1(仅图文,不含视频下载链接)
App V1 的笔记接口,仅适用于图文笔记。返回中不包含视频下载链接,因此不要用它取视频笔记;视频笔记请改用 App V2 的 get_video_note_detail。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_note_info - 官方文档:docs.tikhub.io/310965839e0
- 参数:
note_id(string, 可选)share_text(string, 可选)- 二选一,优先
note_id
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_note_info"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4}
5r = requests.get(url, headers=HEADERS, params=params)
6print(r.json())1.1.3 [Web V3] 获取笔记详情(图文/视频通用)
Web V3 端点,图文/视频通用。需要 xsec_token(从分享链接抽取,见上方"配套工具接口")。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_note_detail - 官方文档:docs.tikhub.io/438852168e0
- 参数:
note_id(string, 必填)xsec_token(string, 必填)
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_note_detail"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "xsec_token": "ABxxxxxxxxxxxxxx",
5}
6r = requests.get(url, headers=HEADERS, params=params)
7print(r.json())1.2 视频笔记
视频笔记不要使用 App V1 的
get_note_info,该接口返回内容里不含视频下载链接。请使用下面的 App V2 或 Web V3。
1.2.1 [App V2] 获取视频笔记详情 ⭐ 推荐
获取视频笔记的完整详情数据(视频地址、封面、时长、标题、正文、互动数据等)。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_video_note_detail - 官方文档:docs.tikhub.io/420136392e0
- 参数:
note_id(string, 可选):例如"697c0eee000000000a03c308"share_text(string, 可选)- 二选一,优先
note_id
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_video_note_detail"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 # "share_text": "https://www.xiaohongshu.com/discovery/item/...",
5}
6r = requests.get(url, headers=HEADERS, params=params)
7print(r.json())1.2.2 [Web V3] 获取笔记详情(视频通用)
与图文同一个端点,按 note_id + xsec_token 调用即可。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_note_detail - 官方文档:docs.tikhub.io/438852168e0
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_note_detail"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "xsec_token": "ABxxxxxxxxxxxxxx",
5}
6r = requests.get(url, headers=HEADERS, params=params)
7print(r.json())2. 用户信息
通过 user_id 获取小红书用户的公开资料(昵称、头像、简介、粉丝数、关注数、笔记数等)。三个系列都提供了用户信息接口;App V2 字段最完整,App V1 / Web V3 适合作备用。
通用建议:优先使用 App V2 系列;只有
user_id时也可走 App V1 / Web V3。
💡 不知道怎么拿到
user_id? 可以先用/api/v1/xiaohongshu/app/get_user_id_and_xsec_token这个工具接口(官方文档),把任意一条小红书用户主页分享链接(长链/短链都行)传进去,就能解析出user_id和xsec_token,再喂给下面的用户信息接口即可。详见下方 2.3。
综合示例:三系列搭配获取用户信息
下面给出一段示意代码,演示**主系列(App V2)→ 备用 1(App V1)→ 备用 2(Web V3)**的搭配调用思路,按照优先级依次尝试,前一个成功就直接返回,失败再降级到下一个。
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9USER_ID = "61b46d790000000010008153"
10
11
12# --- Primary: App V2 / 主系列:App V2 ---
13def fetch_user_by_app_v2(user_id: str):
14 path = "/api/v1/xiaohongshu/app_v2/get_user_info"
15 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
16 params={"user_id": user_id})
17
18
19# --- Fallback 1: App V1 / 备用 1:App V1 ---
20def fetch_user_by_app_v1(user_id: str):
21 path = "/api/v1/xiaohongshu/app/get_user_info"
22 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
23 params={"user_id": user_id})
24
25
26# --- Fallback 2: Web V3 / 备用 2:Web V3 ---
27def fetch_user_by_web_v3(user_id: str):
28 path = "/api/v1/xiaohongshu/web_v3/fetch_user_info"
29 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
30 params={"user_id": user_id})
31
32
33# --- Try all three series in order / 三系列依次尝试 ---
34def get_user_info(user_id: str):
35 # 1) Primary: App V2 / 主系列:App V2
36 try:
37 r = fetch_user_by_app_v2(user_id)
38 if r.ok and r.json().get("code") == 200:
39 return {"source": "app_v2", "data": r.json()}
40 except Exception as e:
41 print("App V2 调用失败:", e)
42
43 # 2) Fallback 1: App V1 / 备用 1:App V1
44 try:
45 r = fetch_user_by_app_v1(user_id)
46 if r.ok and r.json().get("code") == 200:
47 return {"source": "app_v1", "data": r.json()}
48 except Exception as e:
49 print("App V1 调用失败:", e)
50
51 # 3) Fallback 2: Web V3 / 备用 2:Web V3
52 try:
53 r = fetch_user_by_web_v3(user_id)
54 if r.ok and r.json().get("code") == 200:
55 return {"source": "web_v3", "data": r.json()}
56 except Exception as e:
57 print("Web V3 调用失败:", e)
58
59 return None
60
61
62result = get_user_info(USER_ID)
63print(result)提示:上面的成功判断(
code == 200)是示意写法,实际请按各系列返回的 JSON 字段做判断;不同系列返回结构不一致,建议各系列分别写解析逻辑。
2.1 [App V2] 获取用户信息 ⭐ 推荐
获取指定用户的详细信息,包含昵称、头像、简介、粉丝数、关注数、笔记数等。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_user_info - 官方文档:docs.tikhub.io/420136395e0
- 参数:
user_id(string, 可选):用户 ID,例如"61b46d790000000010008153"share_text(string, 可选):小红书用户分享链接(支持 APP / Web 端)- 二选一,优先使用
user_id;都传则以user_id为准
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
5
6url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_user_info"
7params = {
8 "user_id": "61b46d790000000010008153",
9 # "share_text": "https://www.xiaohongshu.com/user/profile/...",
10}
11r = requests.get(url, headers=HEADERS, params=params)
12print(r.json())2.2 [App V1] 获取用户信息
App V1 的用户信息接口。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_user_info - 官方文档:docs.tikhub.io/310965845e0
- 参数:
user_id(string, 必填)
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_user_info"
2params = {
3 "user_id": "61b46d790000000010008153",
4}
5r = requests.get(url, headers=HEADERS, params=params)
6print(r.json())2.3 [App V1] 配套工具:从用户分享链接提取 user_id 和 xsec_token
如果手上只有一条用户主页分享链接(长链/短链都支持),可以先用这个接口解析出 user_id 和 xsec_token,再去调用上面的用户信息接口。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_user_id_and_xsec_token - 官方文档:docs.tikhub.io/364605901e0
- 参数:
share_link(string, 必填):小红书用户分享链接
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_user_id_and_xsec_token"
2params = {
3 "share_link": "https://xhslink.com/m/xxxxx",
4}
5r = requests.get(url, headers=HEADERS, params=params)
6print(r.json())
7# Example response fields / 返回示例字段:
8# {
9# "data": {
10# "user_id": "61b46d790000000010008153",
11# "xsec_token": "ABxxxxxxxxxxxxxx"
12# }
13# }2.4 [Web V3] 获取用户信息
Web V3 的用户公开资料接口,只需要 user_id。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_user_info - 官方文档:docs.tikhub.io/438852177e0
- 参数:
user_id(string, 必填)
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_user_info"
2params = {
3 "user_id": "61b46d790000000010008153",
4}
5r = requests.get(url, headers=HEADERS, params=params)
6print(r.json())3. 用户作品
按 user_id 拉取该用户发布的笔记列表(图文/视频混合),所有接口都使用游标分页(cursor)。App V2 系列额外提供了"用户公开收藏笔记列表"接口(faved notes),App V1 / Web V3 只覆盖"已发布笔记"。
通用建议:优先使用 App V2 系列;只有
user_id时也可走 App V1 / Web V3。💡 不知道怎么拿
user_id?参考上面 2.3 的工具接口(官方文档)。
综合示例:三系列搭配获取用户已发布笔记
下面给出一段示意代码,演示**主系列(App V2)→ 备用 1(App V1)→ 备用 2(Web V3)**的搭配调用思路,按照优先级依次尝试,前一个成功就直接返回,失败再降级到下一个。
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9USER_ID = "61b46d790000000010008153"
10CURSOR = "" # Empty for first request; pass previous response's cursor for pagination / 首次请求留空;翻页时传上一次返回的 cursor
11
12
13# --- Primary: App V2 / 主系列:App V2 ---
14def fetch_user_notes_app_v2(user_id: str, cursor: str = ""):
15 path = "/api/v1/xiaohongshu/app_v2/get_user_posted_notes"
16 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
17 params={"user_id": user_id, "cursor": cursor})
18
19
20# --- Fallback 1: App V1 / 备用 1:App V1 ---
21def fetch_user_notes_app_v1(user_id: str, cursor: str = ""):
22 path = "/api/v1/xiaohongshu/app/get_user_notes"
23 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
24 params={"user_id": user_id, "cursor": cursor})
25
26
27# --- Fallback 2: Web V3 / 备用 2:Web V3 ---
28def fetch_user_notes_web_v3(user_id: str, cursor: str = "", num: int = 30):
29 path = "/api/v1/xiaohongshu/web_v3/fetch_user_notes"
30 return requests.get(f"{BASE_URL}{path}", headers=HEADERS,
31 params={"user_id": user_id, "cursor": cursor, "num": num})
32
33
34# --- Try all three series in order / 三系列依次尝试 ---
35def get_user_notes(user_id: str, cursor: str = ""):
36 # 1) Primary: App V2 / 主系列:App V2
37 try:
38 r = fetch_user_notes_app_v2(user_id, cursor)
39 if r.ok and r.json().get("code") == 200:
40 return {"source": "app_v2", "data": r.json()}
41 except Exception as e:
42 print("App V2 调用失败:", e)
43
44 # 2) Fallback 1: App V1 / 备用 1:App V1
45 try:
46 r = fetch_user_notes_app_v1(user_id, cursor)
47 if r.ok and r.json().get("code") == 200:
48 return {"source": "app_v1", "data": r.json()}
49 except Exception as e:
50 print("App V1 调用失败:", e)
51
52 # 3) Fallback 2: Web V3 / 备用 2:Web V3
53 try:
54 r = fetch_user_notes_web_v3(user_id, cursor)
55 if r.ok and r.json().get("code") == 200:
56 return {"source": "web_v3", "data": r.json()}
57 except Exception as e:
58 print("Web V3 调用失败:", e)
59
60 return None
61
62
63result = get_user_notes(USER_ID, CURSOR)
64print(result)提示:上面的成功判断(
code == 200)是示意写法,实际请按各系列返回的 JSON 字段做判断;不同系列返回结构不一致,建议各系列分别写解析逻辑。
3.1 [App V2] 获取用户已发布笔记列表 ⭐ 推荐
获取指定用户已发布的笔记列表,使用游标分页。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_user_posted_notes - 官方文档:docs.tikhub.io/420136396e0
- 参数:
user_id(string, 可选):用户 ID,例如"61b46d790000000010008153"share_text(string, 可选):小红书用户分享链接(支持 APP / Web 端)- 二选一,优先
user_id;都传则以user_id为准 cursor(string, 可选):分页游标,首次请求留空;翻页时取上一次响应中notes列表最后一条笔记的cursor(路径示例:$.data.data.notes[-1].cursor)
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
5
6url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_user_posted_notes"
7params = {
8 "user_id": "61b46d790000000010008153",
9 "cursor": "", # Empty for first request / 首次留空
10}
11r = requests.get(url, headers=HEADERS, params=params)
12print(r.json())3.2 [App V2] 获取用户公开收藏的笔记列表(仅 App V2)
获取指定用户公开收藏的笔记列表(不是用户自己发布的,而是 ta 收藏的内容),使用游标分页。该接口仅 App V2 提供,App V1 / Web V3 没有对应能力。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_user_faved_notes - 官方文档:docs.tikhub.io/420136397e0
- 参数:
user_id(string, 可选):例如"5a8cf39111be10466d285d6b"share_text(string, 可选)- 二选一,优先
user_id cursor(string, 可选):分页游标,首次留空;翻页传上一页最后一条笔记的note_id
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_user_faved_notes"
2params = {
3 "user_id": "5a8cf39111be10466d285d6b",
4 "cursor": "",
5}
6r = requests.get(url, headers=HEADERS, params=params)
7print(r.json())3.3 [App V1] 获取用户作品列表
App V1 的用户作品接口,只覆盖已发布笔记,使用游标分页。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_user_notes - 官方文档:docs.tikhub.io/310965846e0
- 参数:
user_id(string, 必填)cursor(string, 可选):首次留空;翻页取上一页notes列表最后一条笔记的note_id
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_user_notes"
2params = {
3 "user_id": "61b46d790000000010008153",
4 "cursor": "",
5}
6r = requests.get(url, headers=HEADERS, params=params)
7print(r.json())返回结构(关键字段):
notes[]:笔记数组,每条包含note_id、type(normal=图文 /video=视频)、display_title、desc、liked_count、cover、user等cursor:下一页游标has_more:是否还有更多数据
3.4 [Web V3] 获取用户笔记列表
Web V3 的用户作品接口,使用游标分页,可以指定单页数量(最大 30)。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_user_notes - 官方文档:docs.tikhub.io/438852178e0
- 参数:
user_id(string, 必填)cursor(string, 可选):分页游标num(integer, 可选):单页数量,默认 30,最大 30
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_user_notes"
2params = {
3 "user_id": "61b46d790000000010008153",
4 "cursor": "",
5 "num": 30,
6}
7r = requests.get(url, headers=HEADERS, params=params)
8print(r.json())4. 评论
小红书的评论分为两层:一级评论(笔记下的评论列表) 和 二级评论(某条评论下的回复/子评论列表)。三个系列都提供了这两层接口;App V2 字段最丰富,App V1 / Web V3 适合作备用。
通用建议:优先使用 App V2 系列;Web V3 接口需要
xsec_token(可由分享链接抽取,见 1. 单一笔记 综合示例 / 2.3 工具接口)。
4.1 一级评论(笔记下的评论列表)
综合示例:三系列搭配获取一级评论
下面给出一段示意代码,演示**主系列(App V2)→ 备用 1(App V1)→ 备用 2(Web V3)**的搭配调用思路。
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9NOTE_ID = "697c0eee000000000a03c308"
10XSEC_TOKEN = "ABxxxxxxxxxxxxxx" # Required for Web V3 / Web V3 需要
11
12
13# --- Primary: App V2 / 主系列:App V2 ---
14def fetch_comments_app_v2(note_id: str, cursor: str = "", index: int = 0):
15 path = "/api/v1/xiaohongshu/app_v2/get_note_comments"
16 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
17 "note_id": note_id,
18 "cursor": cursor,
19 "index": index,
20 "pageArea": "UNFOLDED",
21 "sort_strategy": "latest_v2",
22 })
23
24
25# --- Fallback 1: App V1 / 备用 1:App V1 ---
26def fetch_comments_app_v1(note_id: str, start: str = ""):
27 path = "/api/v1/xiaohongshu/app/get_note_comments"
28 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
29 "note_id": note_id,
30 "start": start,
31 "sort_strategy": 1,
32 })
33
34
35# --- Fallback 2: Web V3 / 备用 2:Web V3 ---
36def fetch_comments_web_v3(note_id: str, xsec_token: str, cursor: str = ""):
37 path = "/api/v1/xiaohongshu/web_v3/fetch_note_comments"
38 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
39 "note_id": note_id,
40 "xsec_token": xsec_token,
41 "cursor": cursor,
42 })
43
44
45# --- Try all three series in order / 三系列依次尝试 ---
46def get_note_comments(note_id: str, xsec_token: str):
47 try:
48 r = fetch_comments_app_v2(note_id)
49 if r.ok and r.json().get("code") == 200:
50 return {"source": "app_v2", "data": r.json()}
51 except Exception as e:
52 print("App V2 调用失败:", e)
53
54 try:
55 r = fetch_comments_app_v1(note_id)
56 if r.ok and r.json().get("code") == 200:
57 return {"source": "app_v1", "data": r.json()}
58 except Exception as e:
59 print("App V1 调用失败:", e)
60
61 try:
62 r = fetch_comments_web_v3(note_id, xsec_token)
63 if r.ok and r.json().get("code") == 200:
64 return {"source": "web_v3", "data": r.json()}
65 except Exception as e:
66 print("Web V3 调用失败:", e)
67
68 return None
69
70
71result = get_note_comments(NOTE_ID, XSEC_TOKEN)
72print(result)提示:上面的成功判断(
code == 200)是示意写法,实际请按各系列返回的 JSON 字段做判断。
4.1.1 [App V2] 获取笔记评论列表 ⭐ 推荐
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_note_comments - 官方文档:docs.tikhub.io/420136394e0
- 参数:
note_id(string, 可选):笔记 IDshare_text(string, 可选):分享链接(与note_id二选一,优先note_id)cursor(string, 可选):分页游标,首次留空index(integer, 可选):评论索引,首次传0pageArea(string, 可选):折叠状态,UNFOLDED(默认)/FOLDEDsort_strategy(string, 可选):排序,default/latest_v2(默认) /like_count
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_note_comments"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "cursor": "",
5 "index": 0,
6 "pageArea": "UNFOLDED",
7 "sort_strategy": "latest_v2",
8}
9r = requests.get(url, headers=HEADERS, params=params)
10print(r.json())4.1.2 [App V1] 获取笔记评论
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_note_comments - 官方文档:docs.tikhub.io/310965840e0
- 参数:
note_id(string, 必填)start(string, 可选):翻页游标,首次留空;支持两种格式 —— 简单格式(如"682b0133000000001c03618d"),或 JSON 格式(如{"cursor":"...","index":2,"pageArea":"UNFOLDED"})sort_strategy(integer, 可选):1-默认排序(默认)/2-最新评论
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_note_comments"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "start": "",
5 "sort_strategy": 1,
6}
7r = requests.get(url, headers=HEADERS, params=params)
8print(r.json())4.1.3 [Web V3] 获取笔记评论
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_note_comments - 官方文档:docs.tikhub.io/438852169e0
- 参数:
note_id(string, 必填)xsec_token(string, 必填):可由分享链接抽取cursor(string, 可选):分页游标
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_note_comments"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "xsec_token": "ABxxxxxxxxxxxxxx",
5 "cursor": "",
6}
7r = requests.get(url, headers=HEADERS, params=params)
8print(r.json())4.2 二级评论(子评论 / 回复列表)
获取某条一级评论下的所有回复(子评论),同样三系列覆盖。注意 Web V3 这里参数叫 root_comment_id,其他两个系列叫 comment_id。
综合示例:三系列搭配获取子评论
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9NOTE_ID = "699916e6000000001d0253da"
10COMMENT_ID = "PARENT_COMMENT_ID" # Top-level comment ID / 一级评论 ID
11XSEC_TOKEN = "ABxxxxxxxxxxxxxx" # Required for Web V3 / Web V3 需要
12
13
14def fetch_sub_app_v2(note_id, comment_id, cursor="", index=1):
15 path = "/api/v1/xiaohongshu/app_v2/get_note_sub_comments"
16 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
17 "note_id": note_id,
18 "comment_id": comment_id,
19 "cursor": cursor,
20 "index": index,
21 })
22
23
24def fetch_sub_app_v1(note_id, comment_id, start=""):
25 path = "/api/v1/xiaohongshu/app/get_sub_comments"
26 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
27 "note_id": note_id,
28 "comment_id": comment_id,
29 "start": start,
30 })
31
32
33def fetch_sub_web_v3(note_id, root_comment_id, xsec_token, cursor="", num=10):
34 path = "/api/v1/xiaohongshu/web_v3/fetch_sub_comments"
35 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
36 "note_id": note_id,
37 "root_comment_id": root_comment_id,
38 "xsec_token": xsec_token,
39 "cursor": cursor,
40 "num": num,
41 })
42
43
44def get_sub_comments(note_id, comment_id, xsec_token):
45 try:
46 r = fetch_sub_app_v2(note_id, comment_id)
47 if r.ok and r.json().get("code") == 200:
48 return {"source": "app_v2", "data": r.json()}
49 except Exception as e:
50 print("App V2 调用失败:", e)
51
52 try:
53 r = fetch_sub_app_v1(note_id, comment_id)
54 if r.ok and r.json().get("code") == 200:
55 return {"source": "app_v1", "data": r.json()}
56 except Exception as e:
57 print("App V1 调用失败:", e)
58
59 try:
60 r = fetch_sub_web_v3(note_id, comment_id, xsec_token)
61 if r.ok and r.json().get("code") == 200:
62 return {"source": "web_v3", "data": r.json()}
63 except Exception as e:
64 print("Web V3 调用失败:", e)
65
66 return None
67
68
69result = get_sub_comments(NOTE_ID, COMMENT_ID, XSEC_TOKEN)
70print(result)4.2.1 [App V2] 获取笔记二级评论列表 ⭐ 推荐
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_note_sub_comments - 官方文档:docs.tikhub.io/420748830e0
- 参数:
note_id(string, 可选)share_text(string, 可选)(与note_id二选一,优先note_id)comment_id(string, 必填):父评论 IDcursor(string, 可选):首次留空,翻页时从$.data.cursor中取index(integer, 可选):首次传1,翻页时从$.data.cursor中取
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_note_sub_comments"
2params = {
3 "note_id": "699916e6000000001d0253da",
4 "comment_id": "PARENT_COMMENT_ID",
5 "cursor": "",
6 "index": 1,
7}
8r = requests.get(url, headers=HEADERS, params=params)
9print(r.json())4.2.2 [App V1] 获取子评论
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_sub_comments - 官方文档:docs.tikhub.io/310965841e0
- 参数:
note_id(string, 必填)comment_id(string, 必填):一级评论 IDstart(string, 可选):翻页游标,从上一页最后一条子评论 ID 取(例如"6806642d000000001f01991b")
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_sub_comments"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "comment_id": "PARENT_COMMENT_ID",
5 "start": "",
6}
7r = requests.get(url, headers=HEADERS, params=params)
8print(r.json())4.2.3 [Web V3] 获取子评论
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_sub_comments - 官方文档:docs.tikhub.io/438852170e0
- 参数:
note_id(string, 必填)root_comment_id(string, 必填):父评论 IDxsec_token(string, 必填)num(integer, 可选):返回数量,默认10cursor(string, 可选):分页游标
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_sub_comments"
2params = {
3 "note_id": "697c0eee000000000a03c308",
4 "root_comment_id": "PARENT_COMMENT_ID",
5 "xsec_token": "ABxxxxxxxxxxxxxx",
6 "num": 10,
7 "cursor": "",
8}
9r = requests.get(url, headers=HEADERS, params=params)
10print(r.json())5. 搜索
小红书搜索分两类:搜索笔记 和 搜索用户。
- 搜索笔记:App V2 / App V1 / Web V3 三个系列都提供,App V2 字段最丰富(支持排序、笔记类型、时间筛选、AI 模式等)。
- 搜索用户:只有 App V2 和 Web V3 提供,App V1 没有用户搜索接口。
通用建议:优先使用 App V2 系列;翻页时记得带上首次搜索返回的
search_id/session_id(不同系列参数名略有差异)。
5.1 搜索笔记
综合示例:三系列搭配搜索笔记
下面给出一段示意代码,演示**主系列(App V2)→ 备用 1(App V1)→ 备用 2(Web V3)**的搭配调用思路。
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9KEYWORD = "美食推荐"
10PAGE = 1
11
12
13# --- Primary: App V2 / 主系列:App V2 ---
14def search_notes_app_v2(keyword: str, page: int = 1):
15 path = "/api/v1/xiaohongshu/app_v2/search_notes"
16 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
17 "keyword": keyword,
18 "page": page,
19 "sort_type": "general",
20 "note_type": "不限",
21 "time_filter": "不限",
22 })
23
24
25# --- Fallback 1: App V1 / 备用 1:App V1 ---
26def search_notes_app_v1(keyword: str, page: int = 1):
27 path = "/api/v1/xiaohongshu/app/search_notes"
28 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
29 "keyword": keyword,
30 "page": page,
31 "sort_type": "general",
32 "filter_note_type": "不限",
33 "filter_note_time": "不限",
34 })
35
36
37# --- Fallback 2: Web V3 / 备用 2:Web V3 ---
38def search_notes_web_v3(keyword: str, page: int = 1):
39 path = "/api/v1/xiaohongshu/web_v3/fetch_search_notes"
40 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
41 "keyword": keyword,
42 "page": page,
43 "sort": "general",
44 "note_type": 0,
45 })
46
47
48def search_notes(keyword: str, page: int = 1):
49 try:
50 r = search_notes_app_v2(keyword, page)
51 if r.ok and r.json().get("code") == 200:
52 return {"source": "app_v2", "data": r.json()}
53 except Exception as e:
54 print("App V2 调用失败:", e)
55
56 try:
57 r = search_notes_app_v1(keyword, page)
58 if r.ok and r.json().get("code") == 200:
59 return {"source": "app_v1", "data": r.json()}
60 except Exception as e:
61 print("App V1 调用失败:", e)
62
63 try:
64 r = search_notes_web_v3(keyword, page)
65 if r.ok and r.json().get("code") == 200:
66 return {"source": "web_v3", "data": r.json()}
67 except Exception as e:
68 print("Web V3 调用失败:", e)
69
70 return None
71
72
73result = search_notes(KEYWORD, PAGE)
74print(result)提示:上面的成功判断(
code == 200)是示意写法,实际请按各系列返回的 JSON 字段做判断;翻页时记得把首次响应里的search_id/session_id透传回去。
5.1.1 [App V2] 搜索笔记 ⭐ 推荐
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/search_notes - 官方文档:docs.tikhub.io/420136398e0
- 参数:
keyword(string, 必填):搜索关键词,例如"美食推荐"page(integer, 可选):页码,从1开始sort_type(string, 可选):排序,general(综合,默认)/time_descending(最新)/popularity_descending(最多点赞)/comment_descending(最多评论)/collect_descending(最多收藏)/english_preferred(英文优先)note_type(string, 可选):笔记类型,不限(默认)/视频笔记/普通笔记/直播笔记time_filter(string, 可选):发布时间,不限(默认)/一天内/一周内/半年内search_id(string, 可选):翻页时传首次响应里的值search_session_id(string, 可选):翻页时传首次响应里的值source(string, 可选):来源,默认explore_feedai_mode(integer, 可选):AI 模式,0(关闭,默认)/1(开启)
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/search_notes"
2params = {
3 "keyword": "美食推荐",
4 "page": 1,
5 "sort_type": "general",
6 "note_type": "不限",
7 "time_filter": "不限",
8 # Pass search_id and search_session_id from first response for pagination / 翻页时需要带上首次响应里的 search_id 和 search_session_id
9 # "search_id": "...",
10 # "search_session_id": "...",
11}
12r = requests.get(url, headers=HEADERS, params=params)
13print(r.json())5.1.2 [App V1] 搜索笔记
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/search_notes - 官方文档:docs.tikhub.io/310965843e0
- 参数:
keyword(string, 必填)page(integer, 必填):页码,从1开始search_id(string, 可选):翻页时传首次响应里的值session_id(string, 可选):翻页时传首次响应里的值sort_type(string, 可选):general(默认)/time_descending/popularity_descending/comment_descending/collect_descendingfilter_note_type(string, 可选):不限(默认)/视频笔记/普通笔记filter_note_time(string, 可选):不限(默认)/一天内/一周内/半年内
1url = f"{BASE_URL}/api/v1/xiaohongshu/app/search_notes"
2params = {
3 "keyword": "美食推荐",
4 "page": 1,
5 "sort_type": "general",
6 "filter_note_type": "不限",
7 "filter_note_time": "不限",
8}
9r = requests.get(url, headers=HEADERS, params=params)
10print(r.json())5.1.3 [Web V3] 搜索笔记
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_search_notes - 官方文档:docs.tikhub.io/438852171e0
- 参数:
keyword(string, 必填)page(integer, 可选):默认1sort(string, 可选):general(综合,默认)/time_descending(最新)/popularity_descending(最热)note_type(integer, 可选):0=全部(默认)/1=图文 /2=视频
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_search_notes"
2params = {
3 "keyword": "美食推荐",
4 "page": 1,
5 "sort": "general",
6 "note_type": 0,
7}
8r = requests.get(url, headers=HEADERS, params=params)
9print(r.json())5.2 搜索用户
⚠️ 注意:App V1 没有用户搜索接口,本节只有 App V2 和 Web V3 两个系列。
综合示例:两系列搭配搜索用户
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {
5 "Authorization": "Bearer YOUR_API_KEY",
6 "accept": "application/json",
7}
8
9KEYWORD = "美食博主"
10PAGE = 1
11
12
13# --- Primary: App V2 / 主系列:App V2 ---
14def search_users_app_v2(keyword: str, page: int = 1, search_id: str = ""):
15 path = "/api/v1/xiaohongshu/app_v2/search_users"
16 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
17 "keyword": keyword,
18 "page": page,
19 "search_id": search_id,
20 })
21
22
23# --- Fallback: Web V3 / 备用:Web V3 ---
24def search_users_web_v3(keyword: str, page: int = 1):
25 path = "/api/v1/xiaohongshu/web_v3/fetch_search_users"
26 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
27 "keyword": keyword,
28 "page": page,
29 })
30
31
32def search_users(keyword: str, page: int = 1):
33 try:
34 r = search_users_app_v2(keyword, page)
35 if r.ok and r.json().get("code") == 200:
36 return {"source": "app_v2", "data": r.json()}
37 except Exception as e:
38 print("App V2 调用失败:", e)
39
40 try:
41 r = search_users_web_v3(keyword, page)
42 if r.ok and r.json().get("code") == 200:
43 return {"source": "web_v3", "data": r.json()}
44 except Exception as e:
45 print("Web V3 调用失败:", e)
46
47 return None
48
49
50result = search_users(KEYWORD, PAGE)
51print(result)5.2.1 [App V2] 搜索用户 ⭐ 推荐
每页固定返回 20 条结果,支持分页。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/search_users - 官方文档:docs.tikhub.io/420136399e0
- 参数:
keyword(string, 必填):搜索关键词,例如"美食博主"page(integer, 可选):页码,从1开始search_id(string, 可选):翻页时传首次响应里的值source(string, 可选):来源,默认explore_feed
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/search_users"
2params = {
3 "keyword": "美食博主",
4 "page": 1,
5 # Pass search_id from first response for pagination / 翻页时带上首次响应里的 search_id
6 # "search_id": "...",
7}
8r = requests.get(url, headers=HEADERS, params=params)
9print(r.json())5.2.2 [Web V3] 搜索用户
- 方法:GET
- 路径:
/api/v1/xiaohongshu/web_v3/fetch_search_users - 官方文档:docs.tikhub.io/438852172e0
- 参数:
keyword(string, 必填)page(integer, 可选):默认1
1url = f"{BASE_URL}/api/v1/xiaohongshu/web_v3/fetch_search_users"
2params = {
3 "keyword": "口红",
4 "page": 1,
5}
6r = requests.get(url, headers=HEADERS, params=params)
7print(r.json())6. 话题
小红书话题相关接口分两部分:话题详情 和 话题下的笔记列表。
⚠️ 重要说明:
- Web V3 系列没有话题接口,本节只有 App V2 和 App V1 两个系列。
- App V1 的旧接口
/api/v1/xiaohongshu/app/get_notes_by_topic已弃用,请改用本节的get_topic_notes。- 所有接口都以
page_id(话题/话题标签 ID)作为唯一标识。
6.1 话题详情
仅 App V2 提供话题详情接口(话题名称、浏览量、讨论数、分享信息等)。App V1 / Web V3 没有对应能力。
6.1.1 [App V2] 获取话题详情 ⭐ 仅 App V2
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_topic_info - 官方文档:docs.tikhub.io/420136407e0
- 参数:
page_id(string, 必填):话题页面 ID,例如"5c1cc866febed9000184b7c1"source(string, 可选):来源,默认normalnote_id(string, 可选):来源笔记 ID,从笔记跳转到话题时可传入
1import requests
2
3BASE_URL = "https://api.tikhub.io"
4HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
5
6url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_topic_info"
7params = {
8 "page_id": "5c1cc866febed9000184b7c1",
9 "source": "normal",
10 # "note_id": "...", # Optional: pass when navigating from a note / 从笔记跳转过来时可带
11}
12r = requests.get(url, headers=HEADERS, params=params)
13print(r.json())
14# Response contains page_info (name/views/discussions), tabs, share_info, etc. / 返回包含 page_info(名称/浏览量/讨论数)、tabs、share_info 等6.2 话题笔记列表(话题下的笔记)
获取某个话题/话题标签下的笔记列表。App V2 和 App V1 都提供,但参数和翻页字段差异较大,需要分别适配。
综合示例:双系列搭配获取话题笔记
1import requests
2import time
3
4BASE_URL = "https://api.tikhub.io"
5HEADERS = {
6 "Authorization": "Bearer YOUR_API_KEY",
7 "accept": "application/json",
8}
9
10PAGE_ID = "5c1cc866febed9000184b7c1"
11
12
13# --- Primary: App V2 / 主系列:App V2 ---
14def topic_feed_app_v2(page_id: str, sort: str = "trend"):
15 path = "/api/v1/xiaohongshu/app_v2/get_topic_feed"
16 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
17 "page_id": page_id,
18 "sort": sort, # trend (hottest) / time (latest) | trend(最热) / time(最新)
19 })
20
21
22# --- Fallback: App V1 / 备用:App V1 ---
23def topic_notes_app_v1(page_id: str, sort: str = "hot"):
24 path = "/api/v1/xiaohongshu/app/get_topic_notes"
25 return requests.get(f"{BASE_URL}{path}", headers=HEADERS, params={
26 "page_id": page_id,
27 "first_load_time": str(int(time.time() * 1000)), # Millisecond timestamp / 毫秒级时间戳
28 "sort": sort, # hot (general) / time (latest) / trend (hottest) | hot(综合) / time(最新) / trend(最热)
29 })
30
31
32def get_topic_notes(page_id: str):
33 try:
34 r = topic_feed_app_v2(page_id)
35 if r.ok and r.json().get("code") == 200:
36 return {"source": "app_v2", "data": r.json()}
37 except Exception as e:
38 print("App V2 调用失败:", e)
39
40 try:
41 r = topic_notes_app_v1(page_id)
42 if r.ok and r.json().get("code") == 200:
43 return {"source": "app_v1", "data": r.json()}
44 except Exception as e:
45 print("App V1 调用失败:", e)
46
47 return None
48
49
50result = get_topic_notes(PAGE_ID)
51print(result)提示:上面的成功判断(
code == 200)是示意写法,实际请按各系列返回的 JSON 字段做判断;翻页时记得把对应游标字段透传回去(两个系列字段不同,详见下方)。
6.2.1 [App V2] 获取话题笔记列表 ⭐ 推荐
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app_v2/get_topic_feed - 官方文档:docs.tikhub.io/420136408e0
- 参数:
page_id(string, 必填):话题页面 IDsort(string, 可选):trend(最热,默认)/time(最新)cursor_score(string, 可选):翻页游标分数,翻页时传上一页最后一条 item 的cursor_scorelast_note_id(string, 可选):翻页时传上一页最后一条笔记 ID(items[-1].id)last_note_ct(string, 可选):翻页时传上一页最后一条笔记创建时间(items[-1].create_time)session_id(string, 可选):会话 ID,翻页时保持一致first_load_time(string, 可选):首次加载时间戳,翻页时保持一致source(string, 可选):来源,默认normal
1url = f"{BASE_URL}/api/v1/xiaohongshu/app_v2/get_topic_feed"
2
3# First request: pass only page_id and sort / 首次请求:只传 page_id 和 sort
4params = {
5 "page_id": "5c1cc866febed9000184b7c1",
6 "sort": "trend",
7}
8r = requests.get(url, headers=HEADERS, params=params)
9data = r.json()
10print(data)
11
12# Next page: pass through the following fields from the first response / 翻页请求:从首次响应中取下列字段透传
13# items = data["data"]["items"]
14# next_params = {
15# "page_id": "5c1cc866febed9000184b7c1",
16# "sort": "trend",
17# "cursor_score": items[-1]["cursor_score"],
18# "last_note_id": items[-1]["id"],
19# "last_note_ct": items[-1]["create_time"],
20# "session_id": data["data"]["session_id"],
21# "first_load_time": data["data"]["first_load_time"],
22# }6.2.2 [App V1] 根据话题标签获取作品(替代已弃用的 get_notes_by_topic)
⚠️ App V1 的旧接口
/api/v1/xiaohongshu/app/get_notes_by_topic已弃用,请直接使用本接口。
- 方法:GET
- 路径:
/api/v1/xiaohongshu/app/get_topic_notes - 官方文档:docs.tikhub.io/454758056e0
- 参数:
page_id(string, 必填):话题标签 IDfirst_load_time(string, 必填):首次请求时间戳(毫秒),Python 获取:int(time.time() * 1000)sort(string, 可选):hot(综合,默认)/time(最新)/trend(最热)last_note_ct(string, 可选):翻页时传上一页最后一条笔记的create_timelast_note_id(string, 可选):翻页时传上一页最后一条笔记 IDcursor_score(string, 可选):翻页时传上一页最后一条笔记的cursor_scoresession_id(string, 可选):会话 ID,首次由服务端生成,翻页时回传
1import time
2
3url = f"{BASE_URL}/api/v1/xiaohongshu/app/get_topic_notes"
4
5# First request / 首次请求
6params = {
7 "page_id": "5c1cc866febed9000184b7c1",
8 "first_load_time": str(int(time.time() * 1000)),
9 "sort": "hot",
10}
11r = requests.get(url, headers=HEADERS, params=params)
12data = r.json()
13print(data)
14
15# Next page: keep page_id / first_load_time unchanged, pass session_id and last_* through / 翻页请求:保持 page_id / first_load_time 不变,把 session_id 和 last_* 透传
16# notes = data["data"]["notes"]
17# next_params = {
18# "page_id": "5c1cc866febed9000184b7c1",
19# "first_load_time": params["first_load_time"],
20# "sort": "hot",
21# "session_id": data["data"]["session_id"],
22# "last_note_id": notes[-1]["id"],
23# "last_note_ct": notes[-1]["note"]["create_time"],
24# "cursor_score": notes[-1].get("cursor_score", ""),
25# }