twitter-cli 0.4.5__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/.github/workflows/ci.yml +4 -1
  2. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/.gitignore +1 -0
  3. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/PKG-INFO +64 -29
  4. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/README.md +61 -22
  5. twitter_cli-0.5.0/SCHEMA.md +40 -0
  6. twitter_cli-0.5.0/SKILL.md +292 -0
  7. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/pyproject.toml +14 -7
  8. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/tests/conftest.py +15 -0
  9. twitter_cli-0.5.0/tests/fixtures/followers_page.json +53 -0
  10. twitter_cli-0.5.0/tests/fixtures/home_timeline.json +208 -0
  11. twitter_cli-0.5.0/tests/fixtures/list_timeline.json +75 -0
  12. twitter_cli-0.5.0/tests/fixtures/search_timeline.json +107 -0
  13. twitter_cli-0.5.0/tests/fixtures/tweet_detail.json +118 -0
  14. twitter_cli-0.5.0/tests/test_auth.py +189 -0
  15. twitter_cli-0.5.0/tests/test_cli.py +305 -0
  16. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/tests/test_client.py +86 -2
  17. twitter_cli-0.5.0/tests/test_parser_fixtures.py +93 -0
  18. twitter_cli-0.5.0/tests/test_serialization.py +51 -0
  19. twitter_cli-0.5.0/tests/test_smoke.py +85 -0
  20. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/auth.py +131 -49
  21. twitter_cli-0.5.0/twitter_cli/cli.py +971 -0
  22. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/client.py +366 -560
  23. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/config.py +9 -14
  24. twitter_cli-0.5.0/twitter_cli/constants.py +109 -0
  25. twitter_cli-0.5.0/twitter_cli/exceptions.py +45 -0
  26. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/filter.py +7 -8
  27. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/formatter.py +24 -14
  28. twitter_cli-0.5.0/twitter_cli/graphql.py +221 -0
  29. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/models.py +2 -0
  30. twitter_cli-0.5.0/twitter_cli/output.py +128 -0
  31. twitter_cli-0.5.0/twitter_cli/parser.py +308 -0
  32. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/serialization.py +46 -0
  33. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/uv.lock +91 -1
  34. twitter_cli-0.4.5/SKILL.md +0 -162
  35. twitter_cli-0.4.5/tests/test_cli.py +0 -28
  36. twitter_cli-0.4.5/tests/test_serialization.py +0 -22
  37. twitter_cli-0.4.5/twitter_cli/cli.py +0 -520
  38. twitter_cli-0.4.5/twitter_cli/constants.py +0 -50
  39. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/.github/workflows/publish-clawhub.yml +0 -0
  40. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/.github/workflows/publish.yml +0 -0
  41. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/LICENSE +0 -0
  42. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/config.yaml +0 -0
  43. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/tests/test_config.py +0 -0
  44. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/tests/test_config_normalization.py +0 -0
  45. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/tests/test_filter.py +0 -0
  46. {twitter_cli-0.4.5 → twitter_cli-0.5.0}/twitter_cli/__init__.py +0 -0
@@ -9,6 +9,9 @@ on:
9
9
  jobs:
10
10
  test:
11
11
  runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.8", "3.10", "3.12"]
12
15
  steps:
13
16
  - name: Checkout
14
17
  uses: actions/checkout@v4
@@ -19,7 +22,7 @@ jobs:
19
22
  - name: Setup Python
20
23
  uses: actions/setup-python@v5
21
24
  with:
22
- python-version: "3.12"
25
+ python-version: ${{ matrix.python-version }}
23
26
 
24
27
  - name: Install dependencies
25
28
  run: uv sync --extra dev
@@ -6,4 +6,5 @@ build/
6
6
  .venv/
7
7
  .env
8
8
  *.json
9
+ !tests/fixtures/*.json
9
10
  !config.yaml
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter-cli
3
- Version: 0.4.5
3
+ Version: 0.5.0
4
4
  Summary: A CLI for Twitter/X — feed, bookmarks, and user timeline in terminal
5
5
  Project-URL: Homepage, https://github.com/jackwener/twitter-cli
6
6
  Project-URL: Repository, https://github.com/jackwener/twitter-cli
@@ -14,12 +14,6 @@ Classifier: Environment :: Console
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: License :: OSI Approved :: Apache Software License
16
16
  Classifier: Programming Language :: Python :: 3
17
- Classifier: Programming Language :: Python :: 3.8
18
- Classifier: Programming Language :: Python :: 3.9
19
- Classifier: Programming Language :: Python :: 3.10
20
- Classifier: Programming Language :: Python :: 3.11
21
- Classifier: Programming Language :: Python :: 3.12
22
- Classifier: Programming Language :: Python :: 3.13
23
17
  Classifier: Topic :: Utilities
24
18
  Requires-Python: >=3.8
25
19
  Requires-Dist: beautifulsoup4>=4.12
@@ -30,15 +24,17 @@ Requires-Dist: pyyaml>=6.0
30
24
  Requires-Dist: rich>=13.0
31
25
  Requires-Dist: xclienttransaction>=1.0.1
32
26
  Provides-Extra: dev
27
+ Requires-Dist: mypy<1.15,>=1.14; extra == 'dev'
33
28
  Requires-Dist: pytest>=8.0; extra == 'dev'
34
29
  Requires-Dist: ruff>=0.8; extra == 'dev'
30
+ Requires-Dist: types-pyyaml>=6.0.12; extra == 'dev'
35
31
  Description-Content-Type: text/markdown
36
32
 
37
33
  # twitter-cli
38
34
 
39
35
  [![CI](https://github.com/jackwener/twitter-cli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jackwener/twitter-cli/actions/workflows/ci.yml)
40
- [![PyPI version](https://img.shields.io/pypi/v/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
41
- [![Python versions](https://img.shields.io/pypi/pyversions/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
36
+ [![PyPI version](https://badge.fury.io/py/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
37
+ [![Python](https://img.shields.io/badge/python-%3E%3D3.8-blue.svg)](https://pypi.org/project/twitter-cli/)
42
38
 
43
39
  A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles without API keys.
44
40
 
@@ -46,6 +42,8 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
46
42
 
47
43
  - [xhs-cli](https://github.com/jackwener/xhs-cli) — Xiaohongshu (小红书) CLI for notes and account workflows
48
44
  - [bilibili-cli](https://github.com/jackwener/bilibili-cli) — Bilibili CLI for videos, users, search, and feeds
45
+ - [discord-cli](https://github.com/jackwener/discord-cli) — Discord CLI for local-first sync, search, and export
46
+ - [tg-cli](https://github.com/jackwener/tg-cli) — Telegram CLI for local-first sync, search, and export
49
47
 
50
48
  [English](#english) | [中文](#中文)
51
49
 
@@ -60,19 +58,23 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
60
58
  - Tweet detail: view a tweet and its replies
61
59
  - List timeline: fetch tweets from a Twitter List
62
60
  - User lookup: fetch user profile, tweets, likes, followers, and following
63
- - JSON output: export any data for scripting
61
+ - Structured output: export any data as YAML or JSON for scripting and AI agent integration
64
62
  - Optional scoring filter: rank tweets by engagement weights
63
+ - Structured output contract: [SCHEMA.md](./SCHEMA.md)
64
+
65
+ > **AI Agent Tip:** Prefer `--yaml` for structured output unless a strict JSON parser is required. Non-TTY stdout defaults to YAML automatically. Use `--max` to limit results.
65
66
 
66
67
  **Write:**
67
68
  - Post: create new tweets and replies
68
69
  - Delete: remove your own tweets
69
70
  - Like / Unlike: manage tweet likes
70
71
  - Retweet / Unretweet: manage retweets
71
- - Bookmark: favorite/unfavorite
72
+ - Bookmark: bookmark/unbookmark (`favorite/unfavorite` kept as compatibility aliases)
73
+ - Write commands also support explicit `--json` / `--yaml` output now
72
74
 
73
75
  **Auth & Anti-Detection:**
74
76
  - Cookie auth: use browser cookies or environment variables
75
- - Full cookie forwarding: extracts ALL browser cookies for true browser fingerprint
77
+ - Full cookie forwarding: extracts ALL browser cookies for richer browser context
76
78
  - TLS fingerprint impersonation: `curl_cffi` with dynamic Chrome version matching
77
79
  - `x-client-transaction-id` header generation
78
80
  - Request timing jitter to avoid pattern detection
@@ -119,13 +121,13 @@ twitter feed --json > tweets.json
119
121
  twitter feed --input tweets.json
120
122
 
121
123
  # Bookmarks
122
- twitter favorites
123
- twitter favorites --max 30 --json
124
+ twitter bookmarks
125
+ twitter bookmarks --max 30 --yaml
124
126
 
125
127
  # Search
126
128
  twitter search "Claude Code"
127
129
  twitter search "AI agent" -t Latest --max 50
128
- twitter search "机器学习" --json
130
+ twitter search "机器学习" --yaml
129
131
  twitter search "topic" -o results.json # Save to file
130
132
  twitter search "trending" --filter # Apply ranking filter
131
133
 
@@ -148,13 +150,16 @@ twitter following elonmusk --max 50
148
150
  # Write operations
149
151
  twitter post "Hello from twitter-cli!"
150
152
  twitter post "reply text" --reply-to 1234567890
153
+ twitter post "Hello from twitter-cli!" --json
151
154
  twitter delete 1234567890
152
155
  twitter like 1234567890
156
+ twitter like 1234567890 --yaml
153
157
  twitter unlike 1234567890
154
158
  twitter retweet 1234567890
155
159
  twitter unretweet 1234567890
156
- twitter favorite 1234567890
157
- twitter unfavorite 1234567890
160
+ twitter bookmark 1234567890
161
+ twitter unbookmark 1234567890
162
+ twitter follow elonmusk --json
158
163
  ```
159
164
 
160
165
  ### Authentication
@@ -162,9 +167,9 @@ twitter unfavorite 1234567890
162
167
  twitter-cli uses this auth priority:
163
168
 
164
169
  1. **Environment variables**: `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
165
- 2. **Browser cookies** (recommended): auto-extract from Chrome/Edge/Firefox/Brave
170
+ 2. **Browser cookies** (recommended): auto-extract from Arc/Chrome/Edge/Firefox/Brave
166
171
 
167
- Browser extraction is recommended — it forwards ALL Twitter cookies (not just `auth_token` + `ct0`), making requests indistinguishable from real browser traffic.
172
+ Browser extraction is recommended — it forwards ALL Twitter cookies (not just `auth_token` + `ct0`) and aligns request headers with your local runtime, which is closer to normal browser traffic than minimal cookie auth.
168
173
 
169
174
  After loading cookies, the CLI performs lightweight verification. Commands that require account access fail fast on clear auth errors (`401/403`).
170
175
 
@@ -210,6 +215,10 @@ rateLimit:
210
215
  maxCount: 200 # hard cap on fetched items
211
216
  ```
212
217
 
218
+ Fetch behavior:
219
+
220
+ - `fetch.count` is the default item count for read commands when `--max` is omitted
221
+
213
222
  Filter behavior:
214
223
 
215
224
  - Default behavior: no ranking filter unless `--filter` is passed
@@ -242,8 +251,9 @@ Mode behavior:
242
251
  ### Troubleshooting
243
252
 
244
253
  - `No Twitter cookies found`
245
- - Ensure you are logged in to `x.com` in a supported browser.
254
+ - Ensure you are logged in to `x.com` in a supported browser (Arc/Chrome/Edge/Firefox/Brave).
246
255
  - Or set `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` manually.
256
+ - Run with `-v` to see browser extraction diagnostics.
247
257
 
248
258
  - `Cookie expired or invalid (HTTP 401/403)`
249
259
  - Re-login to `x.com` and retry.
@@ -255,6 +265,8 @@ Mode behavior:
255
265
  - `Invalid tweet JSON file`
256
266
  - Regenerate input using `twitter feed --json > tweets.json`.
257
267
 
268
+ Structured error codes commonly include `not_authenticated`, `not_found`, `invalid_input`, `rate_limited`, and `api_error`.
269
+
258
270
  ### Development
259
271
 
260
272
  ```bash
@@ -266,6 +278,8 @@ uv run ruff check .
266
278
  uv run pytest -q
267
279
  ```
268
280
 
281
+ Current CI validates the project on Python 3.8, 3.10, and 3.12.
282
+
269
283
  ### Project Structure
270
284
 
271
285
  ```text
@@ -273,11 +287,15 @@ twitter_cli/
273
287
  ├── __init__.py
274
288
  ├── cli.py
275
289
  ├── client.py
290
+ ├── graphql.py # GraphQL query IDs, URL building, JS bundle scanning
291
+ ├── parser.py # Tweet, User, Media parsing logic
276
292
  ├── auth.py
277
293
  ├── config.py
278
294
  ├── constants.py
295
+ ├── exceptions.py
279
296
  ├── filter.py
280
297
  ├── formatter.py
298
+ ├── output.py
281
299
  ├── serialization.py
282
300
  └── models.py
283
301
  ```
@@ -319,18 +337,21 @@ After installation, OpenClaw can call `twitter-cli` commands directly.
319
337
  - 推文详情:查看推文及其回复
320
338
  - 列表时间线:获取 Twitter List 的推文
321
339
  - 用户查询:查看用户资料、推文、点赞、粉丝和关注
322
- - JSON 输出:便于脚本处理
340
+ - 结构化输出:支持 YAML 和 JSON,便于脚本处理和 AI agent 集成
341
+
342
+ > **AI Agent 提示:** 需要结构化输出时优先使用 `--yaml`,除非下游必须是 JSON。stdout 不是 TTY 时默认输出 YAML。用 `--max` 控制返回数量。
323
343
 
324
344
  **写入:**
325
345
  - 发推:发布新推文和回复
326
346
  - 删除:删除自己的推文
327
347
  - 点赞 / 取消点赞
328
348
  - 转推 / 取消转推
329
- - 收藏 / 取消收藏:favorite/unfavorite
349
+ - 书签 / 取消书签:bookmark/unbookmark(保留 `favorite/unfavorite` 兼容别名)
350
+ - 写操作现在也显式支持 `--json` / `--yaml`
330
351
 
331
352
  **认证与反风控:**
332
353
  - Cookie 认证:支持环境变量和浏览器自动提取
333
- - 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie
354
+ - 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie,保留更多浏览器上下文
334
355
  - TLS 指纹伪装:`curl_cffi` 动态匹配 Chrome 版本
335
356
  - `x-client-transaction-id` 请求头生成
336
357
  - 请求时序随机化(jitter)
@@ -353,7 +374,7 @@ twitter feed -t following
353
374
  twitter feed --filter
354
375
 
355
376
  # 收藏
356
- twitter favorites
377
+ twitter bookmarks
357
378
 
358
379
  # 搜索
359
380
  twitter search "Claude Code"
@@ -379,13 +400,16 @@ twitter following elonmusk
379
400
  # 写操作
380
401
  twitter post "你好,世界!"
381
402
  twitter post "回复内容" --reply-to 1234567890
403
+ twitter post "你好,世界!" --json
382
404
  twitter delete 1234567890
383
405
  twitter like 1234567890
406
+ twitter like 1234567890 --yaml
384
407
  twitter unlike 1234567890
385
408
  twitter retweet 1234567890
386
409
  twitter unretweet 1234567890
387
- twitter favorite 1234567890
388
- twitter unfavorite 1234567890
410
+ twitter bookmark 1234567890
411
+ twitter unbookmark 1234567890
412
+ twitter follow elonmusk --json
389
413
  ```
390
414
 
391
415
  ### 认证说明
@@ -393,9 +417,9 @@ twitter unfavorite 1234567890
393
417
  认证优先级:
394
418
 
395
419
  1. **环境变量**:`TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
396
- 2. **浏览器提取**(推荐):Chrome/Edge/Firefox/Brave 全量 Cookie 提取
420
+ 2. **浏览器提取**(推荐):Arc/Chrome/Edge/Firefox/Brave 全量 Cookie 提取
397
421
 
398
- 推荐使用浏览器提取方式,会转发所有 Twitter Cookie,让请求和真实浏览器完全一致。
422
+ 推荐使用浏览器提取方式,会转发所有 Twitter Cookie,并按本机运行环境生成语言和平台请求头;它比仅发送 `auth_token` + `ct0` 更接近普通浏览器流量,但不等于完整浏览器自动化。
399
423
 
400
424
  ### 代理支持
401
425
 
@@ -411,6 +435,8 @@ export TWITTER_PROXY=socks5://127.0.0.1:1080
411
435
 
412
436
  ### 筛选算法
413
437
 
438
+ 未传 `--max` 时,所有读取命令默认使用 `config.yaml` 里的 `fetch.count`。
439
+
414
440
  只有在传入 `--filter` 时才会启用筛选评分;默认不筛选。
415
441
 
416
442
  评分公式:
@@ -431,9 +457,11 @@ score = likes_w * likes
431
457
 
432
458
  ### 常见问题
433
459
 
434
- - 报错 `No Twitter cookies found`:请先登录 `x.com` 或手动设置环境变量。
460
+ - 报错 `No Twitter cookies found`:请先登录 `x.com`,并确认浏览器为 Arc/Chrome/Edge/Firefox/Brave 之一,或手动设置环境变量。
461
+ - 如需查看浏览器提取细节,可加 `-v` 打开诊断日志。
435
462
  - 报错 `Cookie expired or invalid`:Cookie 过期,重新登录后重试。
436
463
  - 报错 `Twitter API error 404`:通常是 queryId 轮换,重试即可。
464
+ - 结构化错误码通常会区分 `not_authenticated`、`not_found`、`invalid_input`、`rate_limited`、`api_error`。
437
465
 
438
466
  ### 使用建议(防封号)
439
467
 
@@ -467,3 +495,10 @@ curl -o .agents/skills/twitter-cli/SKILL.md \
467
495
  ```bash
468
496
  clawhub install twitter-cli
469
497
  ```
498
+
499
+ ### 更多工具
500
+
501
+ - [bilibili-cli](https://github.com/jackwener/bilibili-cli) — Bilibili 视频、用户、搜索与动态 CLI
502
+ - [discord-cli](https://github.com/jackwener/discord-cli) — Discord 本地优先同步、检索与导出 CLI
503
+ - [tg-cli](https://github.com/jackwener/tg-cli) — Telegram 本地优先同步、检索与导出 CLI
504
+ - [xhs-cli](https://github.com/jackwener/xhs-cli) — 小红书笔记与账号工作流 CLI
@@ -1,8 +1,8 @@
1
1
  # twitter-cli
2
2
 
3
3
  [![CI](https://github.com/jackwener/twitter-cli/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jackwener/twitter-cli/actions/workflows/ci.yml)
4
- [![PyPI version](https://img.shields.io/pypi/v/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
5
- [![Python versions](https://img.shields.io/pypi/pyversions/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
4
+ [![PyPI version](https://badge.fury.io/py/twitter-cli.svg)](https://pypi.org/project/twitter-cli/)
5
+ [![Python](https://img.shields.io/badge/python-%3E%3D3.8-blue.svg)](https://pypi.org/project/twitter-cli/)
6
6
 
7
7
  A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles without API keys.
8
8
 
@@ -10,6 +10,8 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
10
10
 
11
11
  - [xhs-cli](https://github.com/jackwener/xhs-cli) — Xiaohongshu (小红书) CLI for notes and account workflows
12
12
  - [bilibili-cli](https://github.com/jackwener/bilibili-cli) — Bilibili CLI for videos, users, search, and feeds
13
+ - [discord-cli](https://github.com/jackwener/discord-cli) — Discord CLI for local-first sync, search, and export
14
+ - [tg-cli](https://github.com/jackwener/tg-cli) — Telegram CLI for local-first sync, search, and export
13
15
 
14
16
  [English](#english) | [中文](#中文)
15
17
 
@@ -24,19 +26,23 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
24
26
  - Tweet detail: view a tweet and its replies
25
27
  - List timeline: fetch tweets from a Twitter List
26
28
  - User lookup: fetch user profile, tweets, likes, followers, and following
27
- - JSON output: export any data for scripting
29
+ - Structured output: export any data as YAML or JSON for scripting and AI agent integration
28
30
  - Optional scoring filter: rank tweets by engagement weights
31
+ - Structured output contract: [SCHEMA.md](./SCHEMA.md)
32
+
33
+ > **AI Agent Tip:** Prefer `--yaml` for structured output unless a strict JSON parser is required. Non-TTY stdout defaults to YAML automatically. Use `--max` to limit results.
29
34
 
30
35
  **Write:**
31
36
  - Post: create new tweets and replies
32
37
  - Delete: remove your own tweets
33
38
  - Like / Unlike: manage tweet likes
34
39
  - Retweet / Unretweet: manage retweets
35
- - Bookmark: favorite/unfavorite
40
+ - Bookmark: bookmark/unbookmark (`favorite/unfavorite` kept as compatibility aliases)
41
+ - Write commands also support explicit `--json` / `--yaml` output now
36
42
 
37
43
  **Auth & Anti-Detection:**
38
44
  - Cookie auth: use browser cookies or environment variables
39
- - Full cookie forwarding: extracts ALL browser cookies for true browser fingerprint
45
+ - Full cookie forwarding: extracts ALL browser cookies for richer browser context
40
46
  - TLS fingerprint impersonation: `curl_cffi` with dynamic Chrome version matching
41
47
  - `x-client-transaction-id` header generation
42
48
  - Request timing jitter to avoid pattern detection
@@ -83,13 +89,13 @@ twitter feed --json > tweets.json
83
89
  twitter feed --input tweets.json
84
90
 
85
91
  # Bookmarks
86
- twitter favorites
87
- twitter favorites --max 30 --json
92
+ twitter bookmarks
93
+ twitter bookmarks --max 30 --yaml
88
94
 
89
95
  # Search
90
96
  twitter search "Claude Code"
91
97
  twitter search "AI agent" -t Latest --max 50
92
- twitter search "机器学习" --json
98
+ twitter search "机器学习" --yaml
93
99
  twitter search "topic" -o results.json # Save to file
94
100
  twitter search "trending" --filter # Apply ranking filter
95
101
 
@@ -112,13 +118,16 @@ twitter following elonmusk --max 50
112
118
  # Write operations
113
119
  twitter post "Hello from twitter-cli!"
114
120
  twitter post "reply text" --reply-to 1234567890
121
+ twitter post "Hello from twitter-cli!" --json
115
122
  twitter delete 1234567890
116
123
  twitter like 1234567890
124
+ twitter like 1234567890 --yaml
117
125
  twitter unlike 1234567890
118
126
  twitter retweet 1234567890
119
127
  twitter unretweet 1234567890
120
- twitter favorite 1234567890
121
- twitter unfavorite 1234567890
128
+ twitter bookmark 1234567890
129
+ twitter unbookmark 1234567890
130
+ twitter follow elonmusk --json
122
131
  ```
123
132
 
124
133
  ### Authentication
@@ -126,9 +135,9 @@ twitter unfavorite 1234567890
126
135
  twitter-cli uses this auth priority:
127
136
 
128
137
  1. **Environment variables**: `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
129
- 2. **Browser cookies** (recommended): auto-extract from Chrome/Edge/Firefox/Brave
138
+ 2. **Browser cookies** (recommended): auto-extract from Arc/Chrome/Edge/Firefox/Brave
130
139
 
131
- Browser extraction is recommended — it forwards ALL Twitter cookies (not just `auth_token` + `ct0`), making requests indistinguishable from real browser traffic.
140
+ Browser extraction is recommended — it forwards ALL Twitter cookies (not just `auth_token` + `ct0`) and aligns request headers with your local runtime, which is closer to normal browser traffic than minimal cookie auth.
132
141
 
133
142
  After loading cookies, the CLI performs lightweight verification. Commands that require account access fail fast on clear auth errors (`401/403`).
134
143
 
@@ -174,6 +183,10 @@ rateLimit:
174
183
  maxCount: 200 # hard cap on fetched items
175
184
  ```
176
185
 
186
+ Fetch behavior:
187
+
188
+ - `fetch.count` is the default item count for read commands when `--max` is omitted
189
+
177
190
  Filter behavior:
178
191
 
179
192
  - Default behavior: no ranking filter unless `--filter` is passed
@@ -206,8 +219,9 @@ Mode behavior:
206
219
  ### Troubleshooting
207
220
 
208
221
  - `No Twitter cookies found`
209
- - Ensure you are logged in to `x.com` in a supported browser.
222
+ - Ensure you are logged in to `x.com` in a supported browser (Arc/Chrome/Edge/Firefox/Brave).
210
223
  - Or set `TWITTER_AUTH_TOKEN` and `TWITTER_CT0` manually.
224
+ - Run with `-v` to see browser extraction diagnostics.
211
225
 
212
226
  - `Cookie expired or invalid (HTTP 401/403)`
213
227
  - Re-login to `x.com` and retry.
@@ -219,6 +233,8 @@ Mode behavior:
219
233
  - `Invalid tweet JSON file`
220
234
  - Regenerate input using `twitter feed --json > tweets.json`.
221
235
 
236
+ Structured error codes commonly include `not_authenticated`, `not_found`, `invalid_input`, `rate_limited`, and `api_error`.
237
+
222
238
  ### Development
223
239
 
224
240
  ```bash
@@ -230,6 +246,8 @@ uv run ruff check .
230
246
  uv run pytest -q
231
247
  ```
232
248
 
249
+ Current CI validates the project on Python 3.8, 3.10, and 3.12.
250
+
233
251
  ### Project Structure
234
252
 
235
253
  ```text
@@ -237,11 +255,15 @@ twitter_cli/
237
255
  ├── __init__.py
238
256
  ├── cli.py
239
257
  ├── client.py
258
+ ├── graphql.py # GraphQL query IDs, URL building, JS bundle scanning
259
+ ├── parser.py # Tweet, User, Media parsing logic
240
260
  ├── auth.py
241
261
  ├── config.py
242
262
  ├── constants.py
263
+ ├── exceptions.py
243
264
  ├── filter.py
244
265
  ├── formatter.py
266
+ ├── output.py
245
267
  ├── serialization.py
246
268
  └── models.py
247
269
  ```
@@ -283,18 +305,21 @@ After installation, OpenClaw can call `twitter-cli` commands directly.
283
305
  - 推文详情:查看推文及其回复
284
306
  - 列表时间线:获取 Twitter List 的推文
285
307
  - 用户查询:查看用户资料、推文、点赞、粉丝和关注
286
- - JSON 输出:便于脚本处理
308
+ - 结构化输出:支持 YAML 和 JSON,便于脚本处理和 AI agent 集成
309
+
310
+ > **AI Agent 提示:** 需要结构化输出时优先使用 `--yaml`,除非下游必须是 JSON。stdout 不是 TTY 时默认输出 YAML。用 `--max` 控制返回数量。
287
311
 
288
312
  **写入:**
289
313
  - 发推:发布新推文和回复
290
314
  - 删除:删除自己的推文
291
315
  - 点赞 / 取消点赞
292
316
  - 转推 / 取消转推
293
- - 收藏 / 取消收藏:favorite/unfavorite
317
+ - 书签 / 取消书签:bookmark/unbookmark(保留 `favorite/unfavorite` 兼容别名)
318
+ - 写操作现在也显式支持 `--json` / `--yaml`
294
319
 
295
320
  **认证与反风控:**
296
321
  - Cookie 认证:支持环境变量和浏览器自动提取
297
- - 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie
322
+ - 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie,保留更多浏览器上下文
298
323
  - TLS 指纹伪装:`curl_cffi` 动态匹配 Chrome 版本
299
324
  - `x-client-transaction-id` 请求头生成
300
325
  - 请求时序随机化(jitter)
@@ -317,7 +342,7 @@ twitter feed -t following
317
342
  twitter feed --filter
318
343
 
319
344
  # 收藏
320
- twitter favorites
345
+ twitter bookmarks
321
346
 
322
347
  # 搜索
323
348
  twitter search "Claude Code"
@@ -343,13 +368,16 @@ twitter following elonmusk
343
368
  # 写操作
344
369
  twitter post "你好,世界!"
345
370
  twitter post "回复内容" --reply-to 1234567890
371
+ twitter post "你好,世界!" --json
346
372
  twitter delete 1234567890
347
373
  twitter like 1234567890
374
+ twitter like 1234567890 --yaml
348
375
  twitter unlike 1234567890
349
376
  twitter retweet 1234567890
350
377
  twitter unretweet 1234567890
351
- twitter favorite 1234567890
352
- twitter unfavorite 1234567890
378
+ twitter bookmark 1234567890
379
+ twitter unbookmark 1234567890
380
+ twitter follow elonmusk --json
353
381
  ```
354
382
 
355
383
  ### 认证说明
@@ -357,9 +385,9 @@ twitter unfavorite 1234567890
357
385
  认证优先级:
358
386
 
359
387
  1. **环境变量**:`TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
360
- 2. **浏览器提取**(推荐):Chrome/Edge/Firefox/Brave 全量 Cookie 提取
388
+ 2. **浏览器提取**(推荐):Arc/Chrome/Edge/Firefox/Brave 全量 Cookie 提取
361
389
 
362
- 推荐使用浏览器提取方式,会转发所有 Twitter Cookie,让请求和真实浏览器完全一致。
390
+ 推荐使用浏览器提取方式,会转发所有 Twitter Cookie,并按本机运行环境生成语言和平台请求头;它比仅发送 `auth_token` + `ct0` 更接近普通浏览器流量,但不等于完整浏览器自动化。
363
391
 
364
392
  ### 代理支持
365
393
 
@@ -375,6 +403,8 @@ export TWITTER_PROXY=socks5://127.0.0.1:1080
375
403
 
376
404
  ### 筛选算法
377
405
 
406
+ 未传 `--max` 时,所有读取命令默认使用 `config.yaml` 里的 `fetch.count`。
407
+
378
408
  只有在传入 `--filter` 时才会启用筛选评分;默认不筛选。
379
409
 
380
410
  评分公式:
@@ -395,9 +425,11 @@ score = likes_w * likes
395
425
 
396
426
  ### 常见问题
397
427
 
398
- - 报错 `No Twitter cookies found`:请先登录 `x.com` 或手动设置环境变量。
428
+ - 报错 `No Twitter cookies found`:请先登录 `x.com`,并确认浏览器为 Arc/Chrome/Edge/Firefox/Brave 之一,或手动设置环境变量。
429
+ - 如需查看浏览器提取细节,可加 `-v` 打开诊断日志。
399
430
  - 报错 `Cookie expired or invalid`:Cookie 过期,重新登录后重试。
400
431
  - 报错 `Twitter API error 404`:通常是 queryId 轮换,重试即可。
432
+ - 结构化错误码通常会区分 `not_authenticated`、`not_found`、`invalid_input`、`rate_limited`、`api_error`。
401
433
 
402
434
  ### 使用建议(防封号)
403
435
 
@@ -431,3 +463,10 @@ curl -o .agents/skills/twitter-cli/SKILL.md \
431
463
  ```bash
432
464
  clawhub install twitter-cli
433
465
  ```
466
+
467
+ ### 更多工具
468
+
469
+ - [bilibili-cli](https://github.com/jackwener/bilibili-cli) — Bilibili 视频、用户、搜索与动态 CLI
470
+ - [discord-cli](https://github.com/jackwener/discord-cli) — Discord 本地优先同步、检索与导出 CLI
471
+ - [tg-cli](https://github.com/jackwener/tg-cli) — Telegram 本地优先同步、检索与导出 CLI
472
+ - [xhs-cli](https://github.com/jackwener/xhs-cli) — 小红书笔记与账号工作流 CLI
@@ -0,0 +1,40 @@
1
+ # Structured Output Schema
2
+
3
+ `twitter-cli` uses a shared agent-friendly envelope for machine-readable output.
4
+
5
+ ## Success
6
+
7
+ ```yaml
8
+ ok: true
9
+ schema_version: "1"
10
+ data: ...
11
+ ```
12
+
13
+ ## Error
14
+
15
+ ```yaml
16
+ ok: false
17
+ schema_version: "1"
18
+ error:
19
+ code: api_error
20
+ message: User @foo not found
21
+ ```
22
+
23
+ ## Notes
24
+
25
+ - `--yaml` and `--json` both use this envelope
26
+ - non-TTY stdout defaults to YAML
27
+ - tweet and user lists are returned under `data`
28
+ - `status` returns `data.authenticated` plus `data.user`
29
+ - `whoami` returns `data.user`
30
+ - write commands also support explicit `--json` / `--yaml`
31
+
32
+ ## Error Codes
33
+
34
+ Common structured error codes:
35
+
36
+ - `not_authenticated`
37
+ - `not_found`
38
+ - `invalid_input`
39
+ - `rate_limited`
40
+ - `api_error`