feat(xiaohongshu): multi-backend — OpenCLI / xiaohongshu-mcp / xhs-cli
- backends becomes the ordered candidate list [OpenCLI, xiaohongshu-mcp, xhs-cli]; probing order makes the desktop/server split automatic: OpenCLI never probes alive headless, so servers fall through to xiaohongshu-mcp; first fully-usable candidate wins, fixable (warn) candidates only win when nothing is fully usable - xiaohongshu-mcp probing: HTTP reachability of localhost:18060 (proxy-bypassed) + mcporter config presence; guides through `mcporter config add` when half-wired - opencli backend: treat a sleeping extension service worker as ready — verified live that `daemon status` reports disconnected while any real command wakes it; disambiguate "sleeping" vs "never installed" via the Chrome Extensions directory on disk (fixes active_backend flapping between OpenCLI and xhs-cli across doctor runs) - install: desktop installs OpenCLI; server prints the xiaohongshu-mcp guide (binary to ~/.agent-reach/tools/, QR login, mcporter add); xhs-cli is no longer installed by default (upstream unmaintained since 2026-03) but existing installs keep working as the last candidate - skill/references/social.md: xiaohongshu section rewritten as three backend command groups keyed off `doctor --json` active_backend, including the 120s-timeout and login-first caveats for the mcp path Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,45 +2,66 @@
|
||||
|
||||
小红书、Twitter/X、B站、V2EX、Reddit。
|
||||
|
||||
## 小红书 / XiaoHongShu (xhs-cli)
|
||||
## 小红书 / XiaoHongShu(多后端)
|
||||
|
||||
### 稳定可用的命令
|
||||
小红书有三个后端,**先跑 `agent-reach doctor --json` 看 xiaohongshu 的 `active_backend` 是哪个**,再用对应命令组。
|
||||
|
||||
### 后端 A:OpenCLI(桌面首选,复用浏览器登录态)
|
||||
|
||||
```bash
|
||||
# 搜索笔记(推荐入口)
|
||||
xhs search "query"
|
||||
# 搜索笔记
|
||||
opencli xiaohongshu search "query" -f yaml
|
||||
|
||||
# 阅读笔记详情(必须用搜索结果中的 URL 或 ID,不能裸 note_id)
|
||||
xhs read NOTE_ID_OR_URL
|
||||
# 读笔记正文+互动数据(用搜索结果里的完整 URL,含 xsec_token)
|
||||
opencli xiaohongshu note "NOTE_URL" -f yaml
|
||||
|
||||
# 查看评论
|
||||
xhs comments NOTE_ID_OR_URL
|
||||
# 评论(支持楼中楼)
|
||||
opencli xiaohongshu comments NOTE_ID -f yaml
|
||||
|
||||
# 浏览热门
|
||||
xhs hot
|
||||
# 首页推荐 feed
|
||||
opencli xiaohongshu feed -f yaml
|
||||
|
||||
# 推荐 feed
|
||||
xhs feed
|
||||
# 用户主页公开笔记
|
||||
opencli xiaohongshu user USER_ID -f yaml
|
||||
```
|
||||
|
||||
### 已知不稳定的命令(v0.6.4)
|
||||
> 要求 Chrome 打开且装了 OpenCLI 扩展。报 AUTH_REQUIRED 说明浏览器里没登录小红书,让用户在 Chrome 里登录一次即可。
|
||||
|
||||
### 后端 B:xiaohongshu-mcp(服务器场景)
|
||||
|
||||
```bash
|
||||
# 以下命令当前可能返回 API error,谨慎使用:
|
||||
xhs user USER_ID # 可能返回 {code: -1}
|
||||
xhs user-posts USER_ID # 可能返回 {code: -1}
|
||||
xhs favorites # 可能返回 API error
|
||||
# 未登录时:先查状态,再取二维码给用户扫
|
||||
mcporter call 'xiaohongshu.check_login_status()' --timeout 120000
|
||||
mcporter call 'xiaohongshu.get_login_qrcode()' --timeout 120000
|
||||
|
||||
# 搜索
|
||||
mcporter call 'xiaohongshu.search_feeds(keyword: "query")' --timeout 120000
|
||||
|
||||
# 笔记详情+评论(feed_id 和 xsec_token 从搜索结果取)
|
||||
mcporter call 'xiaohongshu.get_feed_detail(feed_id: "...", xsec_token: "...")' --timeout 120000
|
||||
```
|
||||
|
||||
### 重要注意事项
|
||||
> 首次调用会自动下载约 150MB 无头浏览器,务必带 `--timeout 120000`。未登录时 search 会挂死,先 check_login_status。
|
||||
|
||||
> **安装**: `pipx install xiaohongshu-cli`,然后 `xhs login`(自动从浏览器提取 Cookie)。
|
||||
### 后端 C:xhs-cli(存量备选,上游 2026-03 起停更)
|
||||
|
||||
```bash
|
||||
xhs search "query" # 搜索
|
||||
xhs read NOTE_ID_OR_URL # 读笔记(必须用搜索结果中的 URL/ID,不能裸 note_id)
|
||||
xhs comments NOTE_ID_OR_URL # 评论
|
||||
xhs hot # 热门
|
||||
xhs feed # 推荐
|
||||
```
|
||||
|
||||
> 已知不稳定:`xhs user` / `xhs user-posts` / `xhs favorites` 可能返回 API error(上游停更无人修)。新装用户建议直接走后端 A/B。
|
||||
|
||||
### 通用注意事项
|
||||
|
||||
> **xsec_token 限制**: 小红书强制 xsec_token 机制,**不能直接用裸 note_id 去读**。正确流程:先搜索/feed 拿结果,再用结果中的完整 URL/ID 去读。三个后端都一样。
|
||||
>
|
||||
> **xsec_token 限制**: 小红书强制 xsec_token 机制,**不能直接用裸 note_id 去读**。正确流程是:先 `xhs search` 或 `xhs feed` 获取结果,再用结果中的 URL/ID 去 `xhs read`。直接构造 note_id 会被拦截。
|
||||
> **频率控制**: 高频请求(批量搜索、深翻评论)会触发验证码,平台限制无法绕过。每次操作间隔 2-3 秒。
|
||||
>
|
||||
> **频率控制**: 高频请求(批量搜索、深翻评论)会触发验证码,这是平台限制无法绕过。建议每次操作间隔 2-3 秒。
|
||||
>
|
||||
> **POST 操作风险**: 发帖(post)、评论(comment)、点赞(like) 等写操作在 v0.6.x 可能因签名问题返回 406。如需使用,建议降级到 v0.3.5 (`pipx install xiaohongshu-cli==0.3.5`)。
|
||||
> **写操作(发帖/评论/点赞)**: 建议只读。xhs-cli v0.6.x 写操作可能因签名问题返回 406。
|
||||
|
||||
## Twitter/X (twitter-cli)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user