twitter-cli 0.8.4__tar.gz → 0.9.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.
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/.github/workflows/ci.yml +19 -2
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/PKG-INFO +176 -57
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/README.md +172 -53
- twitter_cli-0.9.0/SCHEMA.md +71 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/SKILL.md +45 -36
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/config.yaml +4 -1
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/pyproject.toml +6 -3
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/conftest.py +29 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/fixtures/list_timeline.json +4 -0
- twitter_cli-0.9.0/tests/test_article.py +53 -0
- twitter_cli-0.9.0/tests/test_article_parsing.py +124 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/test_auth.py +210 -18
- twitter_cli-0.9.0/tests/test_cache.py +101 -0
- twitter_cli-0.9.0/tests/test_cache_permissions.py +90 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/test_cli.py +457 -2
- twitter_cli-0.9.0/tests/test_client.py +2208 -0
- twitter_cli-0.9.0/tests/test_completion.py +47 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/test_config.py +17 -0
- twitter_cli-0.9.0/tests/test_curl_cffi_floor.py +56 -0
- twitter_cli-0.9.0/tests/test_filter.py +88 -0
- twitter_cli-0.9.0/tests/test_output.py +147 -0
- twitter_cli-0.9.0/tests/test_pagination_cap.py +92 -0
- twitter_cli-0.9.0/tests/test_parser_fixtures.py +212 -0
- twitter_cli-0.9.0/tests/test_public_api.py +36 -0
- twitter_cli-0.9.0/tests/test_review_regressions.py +460 -0
- twitter_cli-0.9.0/tests/test_serialization.py +164 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/test_smoke.py +17 -0
- twitter_cli-0.9.0/tests/test_text.py +40 -0
- twitter_cli-0.9.0/tests/test_time_style.py +113 -0
- twitter_cli-0.9.0/tests/test_timeutil.py +73 -0
- twitter_cli-0.9.0/twitter_cli/__init__.py +129 -0
- twitter_cli-0.9.0/twitter_cli/article.py +227 -0
- twitter_cli-0.9.0/twitter_cli/auth.py +943 -0
- twitter_cli-0.9.0/twitter_cli/cache.py +136 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/cli.py +816 -170
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/client.py +786 -146
- twitter_cli-0.9.0/twitter_cli/commands/__init__.py +8 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/config.py +13 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/exceptions.py +30 -1
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/formatter.py +62 -13
- twitter_cli-0.9.0/twitter_cli/graphql.py +439 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/models.py +27 -1
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/output.py +22 -0
- twitter_cli-0.9.0/twitter_cli/parser.py +756 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/serialization.py +97 -20
- twitter_cli-0.9.0/twitter_cli/text.py +180 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/timeutil.py +11 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/uv.lock +147 -100
- twitter_cli-0.8.4/SCHEMA.md +0 -54
- twitter_cli-0.8.4/tests/test_client.py +0 -691
- twitter_cli-0.8.4/tests/test_filter.py +0 -31
- twitter_cli-0.8.4/tests/test_parser_fixtures.py +0 -93
- twitter_cli-0.8.4/tests/test_serialization.py +0 -79
- twitter_cli-0.8.4/twitter_cli/__init__.py +0 -8
- twitter_cli-0.8.4/twitter_cli/auth.py +0 -624
- twitter_cli-0.8.4/twitter_cli/cache.py +0 -66
- twitter_cli-0.8.4/twitter_cli/graphql.py +0 -225
- twitter_cli-0.8.4/twitter_cli/parser.py +0 -315
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/.github/workflows/publish.yml +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/.gitignore +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/AGENTS.md +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/LICENSE +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/fixtures/followers_page.json +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/fixtures/home_timeline.json +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/fixtures/search_timeline.json +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/fixtures/tweet_detail.json +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/test_config_normalization.py +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/tests/test_search.py +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/constants.py +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/filter.py +0 -0
- {twitter_cli-0.8.4 → twitter_cli-0.9.0}/twitter_cli/search.py +0 -0
|
@@ -6,18 +6,31 @@ on:
|
|
|
6
6
|
pull_request:
|
|
7
7
|
workflow_call:
|
|
8
8
|
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: ci-${{ github.workflow }}-${{ github.ref }}
|
|
14
|
+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
15
|
+
|
|
9
16
|
jobs:
|
|
10
17
|
test:
|
|
11
|
-
runs-on: ubuntu-
|
|
18
|
+
runs-on: ubuntu-24.04
|
|
19
|
+
timeout-minutes: 20
|
|
12
20
|
strategy:
|
|
21
|
+
fail-fast: false
|
|
13
22
|
matrix:
|
|
14
|
-
python-version: ["3.10", "3.11", "3.12"]
|
|
23
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
24
|
steps:
|
|
16
25
|
- name: Checkout
|
|
17
26
|
uses: actions/checkout@v4
|
|
27
|
+
with:
|
|
28
|
+
persist-credentials: false
|
|
18
29
|
|
|
19
30
|
- name: Setup uv
|
|
20
31
|
uses: astral-sh/setup-uv@v6
|
|
32
|
+
with:
|
|
33
|
+
enable-cache: true
|
|
21
34
|
|
|
22
35
|
- name: Setup Python
|
|
23
36
|
uses: actions/setup-python@v5
|
|
@@ -26,12 +39,16 @@ jobs:
|
|
|
26
39
|
|
|
27
40
|
- name: Install dependencies
|
|
28
41
|
run: uv sync --extra dev
|
|
42
|
+
timeout-minutes: 10
|
|
29
43
|
|
|
30
44
|
- name: Lint
|
|
31
45
|
run: uv run ruff check .
|
|
46
|
+
timeout-minutes: 5
|
|
32
47
|
|
|
33
48
|
- name: Type check
|
|
34
49
|
run: uv run mypy twitter_cli
|
|
50
|
+
timeout-minutes: 5
|
|
35
51
|
|
|
36
52
|
- name: Test
|
|
37
53
|
run: uv run pytest -q
|
|
54
|
+
timeout-minutes: 10
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: twitter-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.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
|
|
@@ -19,10 +19,10 @@ Requires-Python: >=3.10
|
|
|
19
19
|
Requires-Dist: beautifulsoup4>=4.12
|
|
20
20
|
Requires-Dist: browser-cookie3>=0.19
|
|
21
21
|
Requires-Dist: click>=8.0
|
|
22
|
-
Requires-Dist: curl-cffi>=0.
|
|
22
|
+
Requires-Dist: curl-cffi>=0.15.0
|
|
23
23
|
Requires-Dist: pyyaml>=6.0
|
|
24
24
|
Requires-Dist: rich>=13.0
|
|
25
|
-
Requires-Dist: xclienttransaction>=1.0.
|
|
25
|
+
Requires-Dist: xclienttransaction>=1.0.3
|
|
26
26
|
Provides-Extra: dev
|
|
27
27
|
Requires-Dist: mypy<1.15,>=1.14; extra == 'dev'
|
|
28
28
|
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
@@ -53,22 +53,26 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
|
|
|
53
53
|
|
|
54
54
|
**Read:**
|
|
55
55
|
- Timeline: fetch `for-you` and `following` feeds
|
|
56
|
-
- Bookmarks: list saved tweets
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
56
|
+
- Bookmarks: list saved tweets (with `--cursor` pagination and bookmark folders)
|
|
57
|
+
- Explore News: fetch personalized stories from Explore > News (`twitter news`)
|
|
58
|
+
- Search: find tweets by keyword with Top/Latest/Photos/Videos tabs and advanced filters
|
|
59
|
+
- Tweet detail: view a tweet and its replies (with `--cursor` pagination); use `show <N>` to open tweet #N from the last list output
|
|
60
|
+
- Article: fetch a Twitter Article with rich Draft.js formatting (Markdown blocks, links, inline styles, embedded tweets) and export as Markdown
|
|
60
61
|
- List timeline: fetch tweets from a Twitter List
|
|
61
|
-
- User lookup: fetch user profile, tweets, likes, followers, and following
|
|
62
|
-
- `--full-text
|
|
62
|
+
- User lookup: fetch user profile (by `@handle` or numeric user ID), tweets, likes, followers, and following
|
|
63
|
+
- Display controls: `--full-text` for untruncated tables, `--time relative|absolute|iso` for timestamps, `completion bash|zsh|fish`, and `doctor [--refresh]`
|
|
63
64
|
- Structured output: export any data as YAML or JSON for scripting and AI agent integration
|
|
64
65
|
- Optional scoring filter: rank tweets by engagement weights
|
|
66
|
+
- Python library API: import `TwitterClient`, `get_cookies`, models, and serializers directly from `twitter_cli`
|
|
65
67
|
- Structured output contract: [SCHEMA.md](./SCHEMA.md)
|
|
66
68
|
|
|
67
69
|
> **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.
|
|
68
70
|
|
|
69
71
|
**Write:**
|
|
70
|
-
- Post: create new tweets and replies, with optional
|
|
71
|
-
-
|
|
72
|
+
- Post: create new tweets and replies, with optional images (up to 4) or video (`--video` / `-V`, MP4/MOV/WebM up to 512 MB)
|
|
73
|
+
- Long-form posts: tweets over 280 weighted characters automatically route to `CreateNoteTweet` (X Premium)
|
|
74
|
+
- Article publish: publish X Articles (or drafts) directly from Markdown (`twitter article-publish`)
|
|
75
|
+
- Quote: quote-tweet with optional images or video
|
|
72
76
|
- Delete: remove your own tweets
|
|
73
77
|
- Like / Unlike: manage tweet likes
|
|
74
78
|
- Retweet / Unretweet: manage retweets
|
|
@@ -76,12 +80,12 @@ A terminal-first CLI for Twitter/X: read timelines, bookmarks, and user profiles
|
|
|
76
80
|
- Write commands also support explicit `--json` / `--yaml` output now
|
|
77
81
|
|
|
78
82
|
**Auth & Anti-Detection:**
|
|
79
|
-
- Cookie auth:
|
|
83
|
+
- Cookie auth: browser cookies (Arc, Chrome, Edge, Firefox, Brave, Vivaldi, Zen, custom Chromium dir) or env vars (`TWITTER_COOKIE_STRING` or `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`)
|
|
80
84
|
- Full cookie forwarding: extracts ALL browser cookies for richer browser context
|
|
81
85
|
- TLS fingerprint impersonation: `curl_cffi` with dynamic Chrome version matching
|
|
82
|
-
- `x-client-transaction-id` header generation
|
|
83
|
-
-
|
|
84
|
-
-
|
|
86
|
+
- `x-client-transaction-id` header generation with fail-closed protection on unsigned `POST` mutations
|
|
87
|
+
- Self-healing GraphQL `queryId` resolution with 24h local cache and `TWITTER_QID_<OP>` overrides
|
|
88
|
+
- Request timing jitter and write delays (1.5–4s random) to mitigate rate limits
|
|
85
89
|
- Proxy support via `TWITTER_PROXY` environment variable
|
|
86
90
|
|
|
87
91
|
### Installation
|
|
@@ -129,6 +133,7 @@ twitter feed --filter
|
|
|
129
133
|
```bash
|
|
130
134
|
# Feed
|
|
131
135
|
twitter feed --max 50
|
|
136
|
+
twitter feed --cursor "<next-cursor-from-previous-response>"
|
|
132
137
|
twitter feed --full-text
|
|
133
138
|
twitter feed --output tweets.json
|
|
134
139
|
twitter feed --input tweets.json
|
|
@@ -136,9 +141,14 @@ twitter feed --json # Structured stdout for scripts/agents
|
|
|
136
141
|
|
|
137
142
|
# Bookmarks
|
|
138
143
|
twitter bookmarks
|
|
144
|
+
twitter bookmarks --cursor "<next-cursor-from-previous-response>"
|
|
139
145
|
twitter bookmarks --full-text
|
|
140
146
|
twitter bookmarks --max 30 --yaml
|
|
141
147
|
|
|
148
|
+
# Explore News
|
|
149
|
+
twitter news --max 20
|
|
150
|
+
twitter news --json
|
|
151
|
+
|
|
142
152
|
# Search
|
|
143
153
|
twitter search "Claude Code"
|
|
144
154
|
twitter search "AI agent" -t Latest --max 50
|
|
@@ -151,6 +161,7 @@ twitter search "trending" --filter # Apply ranking filter
|
|
|
151
161
|
|
|
152
162
|
# Tweet detail (view tweet + replies)
|
|
153
163
|
twitter tweet 1234567890
|
|
164
|
+
twitter tweet 1234567890 --cursor "<next-cursor>"
|
|
154
165
|
twitter tweet 1234567890 --full-text
|
|
155
166
|
twitter tweet https://x.com/user/status/1234567890
|
|
156
167
|
|
|
@@ -159,18 +170,22 @@ twitter show 2 # Open tweet #2 from last feed/search
|
|
|
159
170
|
twitter show 2 --full-text # Full text in reply table
|
|
160
171
|
twitter show 2 --json # Structured output
|
|
161
172
|
|
|
162
|
-
# Twitter Article
|
|
173
|
+
# Twitter Article (read & publish)
|
|
163
174
|
twitter article 1234567890
|
|
164
175
|
twitter article https://x.com/user/article/1234567890 --json
|
|
165
176
|
twitter article 1234567890 --markdown
|
|
166
177
|
twitter article 1234567890 --output article.md
|
|
178
|
+
twitter article-publish post.md --title "My Article" # Publish X Article
|
|
179
|
+
twitter article-publish post.md --title "My Draft" --draft # Save as draft
|
|
167
180
|
|
|
168
181
|
# List timeline
|
|
169
182
|
twitter list 1539453138322673664
|
|
183
|
+
twitter list 1539453138322673664 --cursor "<next-cursor-from-previous-response>"
|
|
170
184
|
twitter list 1539453138322673664 --full-text
|
|
171
185
|
|
|
172
|
-
# User
|
|
186
|
+
# User (accepts @handle or numeric user ID)
|
|
173
187
|
twitter user elonmusk
|
|
188
|
+
twitter user 44196397
|
|
174
189
|
twitter user-posts elonmusk --max 20
|
|
175
190
|
twitter user-posts elonmusk --full-text
|
|
176
191
|
twitter user-posts elonmusk -o tweets.json
|
|
@@ -184,6 +199,7 @@ twitter following elonmusk --max 50
|
|
|
184
199
|
twitter post "Hello from twitter-cli!"
|
|
185
200
|
twitter post "Hello!" --image photo.jpg # Post with image
|
|
186
201
|
twitter post "Gallery" -i a.png -i b.jpg -i c.webp # Up to 4 images
|
|
202
|
+
twitter post "Demo clip" --video clip.mp4 # Post with video (up to 512 MB)
|
|
187
203
|
twitter post "reply text" --reply-to 1234567890
|
|
188
204
|
twitter reply 1234567890 "Nice!" -i screenshot.png # Reply with image
|
|
189
205
|
twitter quote 1234567890 "Look" -i chart.png # Quote with image
|
|
@@ -197,16 +213,39 @@ twitter unretweet 1234567890
|
|
|
197
213
|
twitter bookmark 1234567890
|
|
198
214
|
twitter unbookmark 1234567890
|
|
199
215
|
twitter follow elonmusk --json
|
|
216
|
+
|
|
217
|
+
# Display, completion & diagnostics
|
|
218
|
+
twitter --time relative feed # relative | absolute | iso
|
|
219
|
+
twitter completion zsh # bash | zsh | fish
|
|
220
|
+
twitter doctor # Check deps, config, auth presence, caches
|
|
221
|
+
twitter doctor --refresh # Refresh cached GraphQL query IDs
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Python Library Usage
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from twitter_cli import TwitterClient, get_cookies
|
|
228
|
+
|
|
229
|
+
cookies = get_cookies()
|
|
230
|
+
client = TwitterClient(
|
|
231
|
+
cookies["auth_token"],
|
|
232
|
+
cookies["ct0"],
|
|
233
|
+
cookie_string=cookies.get("cookie_string"),
|
|
234
|
+
)
|
|
235
|
+
tweets = client.fetch_home_timeline(count=20)
|
|
236
|
+
for tweet in tweets:
|
|
237
|
+
print(f"@{tweet.author.screen_name}: {tweet.text[:80]}")
|
|
200
238
|
```
|
|
201
239
|
|
|
202
240
|
### Authentication
|
|
203
241
|
|
|
204
242
|
twitter-cli uses this auth priority:
|
|
205
243
|
|
|
206
|
-
1. **
|
|
207
|
-
2. **
|
|
244
|
+
1. **Full cookie string**: `TWITTER_COOKIE_STRING` (full `Cookie:` header; auto-extracts `auth_token` + `ct0` while keeping all session cookies — great for remote servers, SigCLI, or Windows Chrome >=127)
|
|
245
|
+
2. **Environment variables**: `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
|
|
246
|
+
3. **Browser cookies** (recommended locally): auto-extract from Arc, Chrome, Edge, Firefox, Brave, Vivaldi, or Zen
|
|
208
247
|
|
|
209
|
-
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.
|
|
248
|
+
Browser extraction is recommended locally — 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.
|
|
210
249
|
|
|
211
250
|
**Chrome multi-profile**: All Chrome profiles are scanned automatically. To specify a profile:
|
|
212
251
|
|
|
@@ -214,14 +253,24 @@ Browser extraction is recommended — it forwards ALL Twitter cookies (not just
|
|
|
214
253
|
TWITTER_CHROME_PROFILE="Profile 2" twitter feed
|
|
215
254
|
```
|
|
216
255
|
|
|
256
|
+
**Custom Chromium directory:** For Chromium, Opera, Brave/Chrome custom data dirs, or portable builds:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
TWITTER_CHROMIUM_USER_DATA_DIR="/path/to/User Data" twitter feed
|
|
260
|
+
```
|
|
261
|
+
|
|
217
262
|
**Browser priority:** If you have multiple browsers, set `TWITTER_BROWSER` to try a specific browser first:
|
|
218
263
|
|
|
219
264
|
```bash
|
|
220
|
-
TWITTER_BROWSER=chrome twitter feed # Supported: arc, chrome, edge, firefox, brave
|
|
265
|
+
TWITTER_BROWSER=chrome twitter feed # Supported: arc, chrome, edge, firefox, brave, vivaldi, zen
|
|
221
266
|
```
|
|
222
267
|
|
|
223
268
|
After loading cookies, the CLI performs lightweight verification. Commands that require account access fail fast on clear auth errors (`401/403`).
|
|
224
269
|
|
|
270
|
+
**Advanced GraphQL & Transaction env vars:**
|
|
271
|
+
- `TWITTER_QID_<OPERATION>=<queryId>` — override a specific GraphQL queryId (e.g. `TWITTER_QID_HomeTimeline=...`)
|
|
272
|
+
- `TWITTER_ALLOW_UNSIGNED=1` — opt-in bypass if `x-client-transaction-id` cannot be generated on write (`POST`) requests (fails closed by default to prevent 226 anti-bot flags)
|
|
273
|
+
|
|
225
274
|
### Proxy Support
|
|
226
275
|
|
|
227
276
|
Set `TWITTER_PROXY` to route all requests through a proxy:
|
|
@@ -238,12 +287,15 @@ Using a proxy can help reduce IP-based rate limiting risks.
|
|
|
238
287
|
|
|
239
288
|
### Configuration
|
|
240
289
|
|
|
241
|
-
Create `config.yaml` in your working directory:
|
|
290
|
+
Create `config.yaml` in your working directory or `~/.twitter-cli/config.yaml` (search order: explicit path → `./config.yaml` → `~/.twitter-cli/config.yaml` → built-in defaults):
|
|
242
291
|
|
|
243
292
|
```yaml
|
|
244
293
|
fetch:
|
|
245
294
|
count: 50
|
|
246
295
|
|
|
296
|
+
display:
|
|
297
|
+
time: "relative" # "relative" | "absolute" | "iso"
|
|
298
|
+
|
|
247
299
|
filter:
|
|
248
300
|
mode: "topN" # "topN" | "score" | "all"
|
|
249
301
|
topN: 20
|
|
@@ -261,7 +313,7 @@ rateLimit:
|
|
|
261
313
|
requestDelay: 2.5 # base delay between requests (randomized ×0.7–1.5)
|
|
262
314
|
maxRetries: 3 # retry count on rate limit (429)
|
|
263
315
|
retryBaseDelay: 5.0 # base delay for exponential backoff
|
|
264
|
-
maxCount: 200 #
|
|
316
|
+
maxCount: 200 # default pagination cap (explicit --max can exceed up to 10,000)
|
|
265
317
|
```
|
|
266
318
|
|
|
267
319
|
Fetch behavior:
|
|
@@ -308,9 +360,9 @@ Mode behavior:
|
|
|
308
360
|
### Troubleshooting
|
|
309
361
|
|
|
310
362
|
- `No Twitter cookies found`
|
|
311
|
-
- Ensure you are logged in to `x.com` in a supported browser (Arc/Chrome/Edge/Firefox/Brave)
|
|
312
|
-
- Or set `TWITTER_AUTH_TOKEN`
|
|
313
|
-
- Run with `-v` to see
|
|
363
|
+
- Ensure you are logged in to `x.com` in a supported browser (Arc/Chrome/Edge/Firefox/Brave/Vivaldi/Zen) or point to a custom directory with `TWITTER_CHROMIUM_USER_DATA_DIR`.
|
|
364
|
+
- Or set `TWITTER_COOKIE_STRING` (recommended for headless/Windows Chrome >=127) or `TWITTER_AUTH_TOKEN` + `TWITTER_CT0` manually.
|
|
365
|
+
- Run with `-v` or `twitter doctor` to see diagnostics.
|
|
314
366
|
|
|
315
367
|
- `Cookie expired or invalid (HTTP 401/403)`
|
|
316
368
|
- Re-login to `x.com` and retry.
|
|
@@ -330,9 +382,15 @@ Mode behavior:
|
|
|
330
382
|
- `Invalid tweet JSON file`
|
|
331
383
|
- Regenerate input using `twitter feed --json > tweets.json`.
|
|
332
384
|
|
|
385
|
+
- **Windows: no output captured by pipe/subprocess** (AI agent integration)
|
|
386
|
+
- This is a **ConPTY** issue, not a twitter-cli bug. Windows Terminal's ConPTY pseudo-terminal can intercept pipe output from commands with network latency.
|
|
387
|
+
- **Fix**: Use **Git Bash** as your terminal shell and set `"windowsEnableConpty": false` in your terminal settings.
|
|
388
|
+
- If disabling ConPTY with PowerShell, emoji output may fail with `UnicodeEncodeError: 'gbk'`. Git Bash handles UTF-8 natively.
|
|
389
|
+
- Standard `subprocess.run(capture_output=True)` and file redirection (`> file 2>&1`) work correctly regardless of ConPTY.
|
|
390
|
+
|
|
333
391
|
|
|
334
392
|
|
|
335
|
-
Structured error codes commonly include `not_authenticated`, `not_found`, `invalid_input`, `rate_limited`, and `api_error`.
|
|
393
|
+
Structured error codes commonly include `not_authenticated`, `not_found`, `invalid_input`, `rate_limited`, `network_error`, `query_id_error`, `media_upload_error`, and `api_error`.
|
|
336
394
|
|
|
337
395
|
### Development
|
|
338
396
|
|
|
@@ -345,26 +403,31 @@ uv run ruff check .
|
|
|
345
403
|
uv run pytest -q
|
|
346
404
|
```
|
|
347
405
|
|
|
348
|
-
Current CI validates the project on Python 3.
|
|
406
|
+
Current CI validates the project on Python 3.10, 3.11, 3.12, and 3.13.
|
|
349
407
|
|
|
350
408
|
### Project Structure
|
|
351
409
|
|
|
352
410
|
```text
|
|
353
411
|
twitter_cli/
|
|
354
|
-
├── __init__.py
|
|
355
|
-
├──
|
|
356
|
-
├──
|
|
357
|
-
├──
|
|
358
|
-
├──
|
|
359
|
-
├──
|
|
360
|
-
├── config.py
|
|
412
|
+
├── __init__.py # Public Python library exports
|
|
413
|
+
├── article.py # Markdown -> Draft.js content_state builder for X Articles
|
|
414
|
+
├── auth.py # Browser cookie extraction & env auth
|
|
415
|
+
├── cache.py # Owner-only local cache helpers
|
|
416
|
+
├── cli.py # Click CLI commands
|
|
417
|
+
├── client.py # HTTP/GraphQL/media client & ClientTransaction bootstrap
|
|
418
|
+
├── config.py # YAML configuration loader
|
|
361
419
|
├── constants.py
|
|
362
420
|
├── exceptions.py
|
|
363
421
|
├── filter.py
|
|
364
422
|
├── formatter.py
|
|
423
|
+
├── graphql.py # GraphQL query IDs, disk cache, live JS bundle scanning
|
|
424
|
+
├── models.py
|
|
365
425
|
├── output.py
|
|
426
|
+
├── parser.py # Tweet, User, Media, Article Draft.js parsing
|
|
427
|
+
├── search.py # Advanced search query builder
|
|
366
428
|
├── serialization.py
|
|
367
|
-
|
|
429
|
+
├── text.py # twitter-text v3 weighted character length
|
|
430
|
+
└── timeutil.py
|
|
368
431
|
```
|
|
369
432
|
|
|
370
433
|
### Use as AI Agent Skill
|
|
@@ -400,20 +463,24 @@ git clone git@github.com:jackwener/twitter-cli.git .agents/skills/twitter-cli
|
|
|
400
463
|
|
|
401
464
|
**读取:**
|
|
402
465
|
- 时间线读取:支持 `for-you` 和 `following`
|
|
403
|
-
-
|
|
404
|
-
-
|
|
405
|
-
-
|
|
406
|
-
-
|
|
466
|
+
- 收藏读取:查看账号书签推文(支持 `--cursor` 翻页及书签文件夹)
|
|
467
|
+
- Explore 新闻:`twitter news` 获取个性化新闻摘要
|
|
468
|
+
- 搜索:按关键词搜索推文,支持 Top/Latest/Photos/Videos 与高级过滤
|
|
469
|
+
- 推文详情:查看推文及其回复(支持 `--cursor` 翻页);用 `show <N>` 可直接打开上次列表里的第 N 条推文
|
|
470
|
+
- 文章读取:获取 Twitter 长文(完整保留 Draft.js Markdown/链接/行内样式/嵌入推文),并导出为 Markdown
|
|
407
471
|
- 列表时间线:获取 Twitter List 的推文
|
|
408
|
-
-
|
|
409
|
-
-
|
|
472
|
+
- 用户查询:支持 `@handle` 或纯数字 user ID 查询资料、推文、点赞、粉丝和关注
|
|
473
|
+
- 展示与工具:`--full-text` 关闭正文截断、`--time relative|absolute|iso` 控制时间格式、`completion bash|zsh|fish`、`doctor [--refresh]`
|
|
410
474
|
- 结构化输出:支持 YAML 和 JSON,便于脚本处理和 AI agent 集成
|
|
475
|
+
- Python 库 API:可直接 `from twitter_cli import TwitterClient, get_cookies` 调用
|
|
411
476
|
|
|
412
477
|
> **AI Agent 提示:** 需要结构化输出时优先使用 `--yaml`,除非下游必须是 JSON。stdout 不是 TTY 时默认输出 YAML。用 `--max` 控制返回数量。
|
|
413
478
|
|
|
414
479
|
**写入:**
|
|
415
|
-
- 发推:发布新推文和回复,支持附带图片(最多 4
|
|
416
|
-
-
|
|
480
|
+
- 发推:发布新推文和回复,支持附带图片(最多 4 张)或视频(`--video` / `-V`,MP4/MOV/WebM,最大 512 MB)
|
|
481
|
+
- 长推文自动适配:超过 280 加权字符时自动切换 `CreateNoteTweet`(需 X Premium)
|
|
482
|
+
- 长文发布:`twitter article-publish` 直接从 Markdown 发布 X Article 或保存草稿
|
|
483
|
+
- 引用推文:带评论的转发,支持附带图片或视频
|
|
417
484
|
- 删除:删除自己的推文
|
|
418
485
|
- 点赞 / 取消点赞
|
|
419
486
|
- 转推 / 取消转推
|
|
@@ -421,12 +488,12 @@ git clone git@github.com:jackwener/twitter-cli.git .agents/skills/twitter-cli
|
|
|
421
488
|
- 写操作现在也显式支持 `--json` / `--yaml`
|
|
422
489
|
|
|
423
490
|
**认证与反风控:**
|
|
424
|
-
- Cookie
|
|
491
|
+
- Cookie 认证:支持环境变量(`TWITTER_COOKIE_STRING` 或 `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`)和浏览器自动提取(Arc/Chrome/Edge/Firefox/Brave/Vivaldi/Zen 及自定义 Chromium 目录)
|
|
425
492
|
- 完整 Cookie 转发:提取浏览器中所有 Twitter Cookie,保留更多浏览器上下文
|
|
426
493
|
- TLS 指纹伪装:`curl_cffi` 动态匹配 Chrome 版本
|
|
427
|
-
- `x-client-transaction-id`
|
|
428
|
-
-
|
|
429
|
-
-
|
|
494
|
+
- `x-client-transaction-id` 请求头生成,写操作缺失签名时默认 fail-closed 拦截以防 226 风控
|
|
495
|
+
- GraphQL `queryId` 24 小时本地缓存、实时 bundle 刷新与 `TWITTER_QID_<OP>` 覆盖
|
|
496
|
+
- 请求时序随机化(jitter)与写操作随机延迟(1.5–4 秒),降低频率风控
|
|
430
497
|
- 代理支持:`TWITTER_PROXY` 环境变量
|
|
431
498
|
|
|
432
499
|
### 安装
|
|
@@ -453,11 +520,16 @@ twitter feed
|
|
|
453
520
|
twitter feed -t following
|
|
454
521
|
twitter feed --filter
|
|
455
522
|
twitter feed --full-text
|
|
523
|
+
twitter feed --cursor "<上一页返回的 nextCursor>"
|
|
456
524
|
|
|
457
525
|
# 收藏
|
|
458
526
|
twitter bookmarks
|
|
527
|
+
twitter bookmarks --cursor "<上一页返回的 nextCursor>"
|
|
459
528
|
twitter bookmarks --full-text
|
|
460
529
|
|
|
530
|
+
# Explore 新闻
|
|
531
|
+
twitter news --max 20
|
|
532
|
+
|
|
461
533
|
# 搜索
|
|
462
534
|
twitter search "Claude Code"
|
|
463
535
|
twitter search "AI agent" -t Latest --max 50
|
|
@@ -467,6 +539,7 @@ twitter search "trending" --filter # 启用排序筛选
|
|
|
467
539
|
|
|
468
540
|
# 推文详情
|
|
469
541
|
twitter tweet 1234567890
|
|
542
|
+
twitter tweet 1234567890 --cursor "<nextCursor>"
|
|
470
543
|
twitter tweet 1234567890 --full-text
|
|
471
544
|
|
|
472
545
|
# 通过序号打开上次列表里的推文
|
|
@@ -474,18 +547,22 @@ twitter show 2 # 打开上次 feed/search 的第 2 条
|
|
|
474
547
|
twitter show 2 --full-text # 在回复表格里显示完整正文
|
|
475
548
|
twitter show 2 --json # 结构化输出
|
|
476
549
|
|
|
477
|
-
# Twitter
|
|
550
|
+
# Twitter 长文(读取与发布)
|
|
478
551
|
twitter article 1234567890
|
|
479
552
|
twitter article https://x.com/user/article/1234567890 --json
|
|
480
553
|
twitter article 1234567890 --markdown
|
|
481
554
|
twitter article 1234567890 --output article.md
|
|
555
|
+
twitter article-publish post.md --title "我的长文"
|
|
556
|
+
twitter article-publish post.md --title "草稿标题" --draft
|
|
482
557
|
|
|
483
558
|
# 列表时间线
|
|
484
559
|
twitter list 1539453138322673664
|
|
560
|
+
twitter list 1539453138322673664 --cursor "<上一页返回的 nextCursor>"
|
|
485
561
|
twitter list 1539453138322673664 --full-text
|
|
486
562
|
|
|
487
|
-
#
|
|
563
|
+
# 用户(支持 @handle 或纯数字 ID)
|
|
488
564
|
twitter user elonmusk
|
|
565
|
+
twitter user 44196397
|
|
489
566
|
twitter user-posts elonmusk --max 20
|
|
490
567
|
twitter user-posts elonmusk --full-text
|
|
491
568
|
twitter user-posts elonmusk -o tweets.json
|
|
@@ -499,6 +576,7 @@ twitter following elonmusk
|
|
|
499
576
|
twitter post "你好,世界!"
|
|
500
577
|
twitter post "发图" --image photo.jpg # 带图发推
|
|
501
578
|
twitter post "多图" -i a.png -i b.jpg -i c.webp # 最多 4 张图片
|
|
579
|
+
twitter post "发视频" --video clip.mp4 # 带视频发推(最大 512 MB)
|
|
502
580
|
twitter post "回复内容" --reply-to 1234567890
|
|
503
581
|
twitter reply 1234567890 "回复" -i screenshot.png # 带图回复
|
|
504
582
|
twitter quote 1234567890 "评论" -i chart.png # 带图引用
|
|
@@ -512,14 +590,37 @@ twitter unretweet 1234567890
|
|
|
512
590
|
twitter bookmark 1234567890
|
|
513
591
|
twitter unbookmark 1234567890
|
|
514
592
|
twitter follow elonmusk --json
|
|
593
|
+
|
|
594
|
+
# 展示、补全与诊断
|
|
595
|
+
twitter --time relative feed # relative | absolute | iso
|
|
596
|
+
twitter completion zsh # bash | zsh | fish
|
|
597
|
+
twitter doctor # 检查依赖、配置、认证状态与缓存
|
|
598
|
+
twitter doctor --refresh # 检查环境并刷新 GraphQL queryId 缓存
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### Python 库调用
|
|
602
|
+
|
|
603
|
+
```python
|
|
604
|
+
from twitter_cli import TwitterClient, get_cookies
|
|
605
|
+
|
|
606
|
+
cookies = get_cookies()
|
|
607
|
+
client = TwitterClient(
|
|
608
|
+
cookies["auth_token"],
|
|
609
|
+
cookies["ct0"],
|
|
610
|
+
cookie_string=cookies.get("cookie_string"),
|
|
611
|
+
)
|
|
612
|
+
tweets = client.fetch_home_timeline(count=20)
|
|
613
|
+
for tweet in tweets:
|
|
614
|
+
print(f"@{tweet.author.screen_name}: {tweet.text[:80]}")
|
|
515
615
|
```
|
|
516
616
|
|
|
517
617
|
### 认证说明
|
|
518
618
|
|
|
519
619
|
认证优先级:
|
|
520
620
|
|
|
521
|
-
1.
|
|
522
|
-
2.
|
|
621
|
+
1. **完整 Cookie 字符串**:`TWITTER_COOKIE_STRING`(完整 `Cookie:` 请求头,自动解析 `auth_token` + `ct0` 并保留全部会话 Cookie,适合云端/Windows Chrome >=127)
|
|
622
|
+
2. **环境变量**:`TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
|
|
623
|
+
3. **浏览器提取**(本地推荐):Arc/Chrome/Edge/Firefox/Brave/Vivaldi/Zen 全量 Cookie 提取
|
|
523
624
|
|
|
524
625
|
推荐使用浏览器提取方式,会转发所有 Twitter Cookie,并按本机运行环境生成语言和平台请求头;它比仅发送 `auth_token` + `ct0` 更接近普通浏览器流量,但不等于完整浏览器自动化。
|
|
525
626
|
|
|
@@ -529,12 +630,24 @@ twitter follow elonmusk --json
|
|
|
529
630
|
TWITTER_CHROME_PROFILE="Profile 2" twitter feed
|
|
530
631
|
```
|
|
531
632
|
|
|
633
|
+
**自定义 Chromium 目录**:适用于 Chromium、Opera 或自定义数据目录:
|
|
634
|
+
|
|
635
|
+
```bash
|
|
636
|
+
TWITTER_CHROMIUM_USER_DATA_DIR="/path/to/User Data" twitter feed
|
|
637
|
+
```
|
|
638
|
+
|
|
532
639
|
**浏览器优先级**:如果有多个浏览器,可通过 `TWITTER_BROWSER` 指定优先尝试的浏览器:
|
|
533
640
|
|
|
534
641
|
```bash
|
|
535
|
-
TWITTER_BROWSER=chrome twitter feed # 支持: arc, chrome, edge, firefox, brave
|
|
642
|
+
TWITTER_BROWSER=chrome twitter feed # 支持: arc, chrome, edge, firefox, brave, vivaldi, zen
|
|
536
643
|
```
|
|
537
644
|
|
|
645
|
+
**高级 GraphQL 与签名环境变量**:
|
|
646
|
+
- `TWITTER_QID_<OPERATION>=<queryId>` — 运行时覆盖指定 GraphQL operation 的 queryId(例如 `TWITTER_QID_HomeTimeline=...`)
|
|
647
|
+
- `TWITTER_ALLOW_UNSIGNED=1` — 当写操作(`POST`)无法生成 `x-client-transaction-id` 时默认 fail-closed 拦截以防 226 风控,仅调试时可显式设此变量绕过
|
|
648
|
+
|
|
649
|
+
**配置文件**:查找顺序为显式路径 → `./config.yaml` → `~/.twitter-cli/config.yaml` → 内置默认配置。可在 `display.time` 设置默认时间格式(`relative` / `absolute` / `iso`),显式 `--max` 可突破默认 `rateLimit.maxCount`(200)直到 10,000 安全上限。结构化输出规范见 [SCHEMA.md](./SCHEMA.md)。
|
|
650
|
+
|
|
538
651
|
### 代理支持
|
|
539
652
|
|
|
540
653
|
设置 `TWITTER_PROXY` 环境变量即可:
|
|
@@ -573,8 +686,8 @@ score = likes_w * likes
|
|
|
573
686
|
|
|
574
687
|
### 常见问题
|
|
575
688
|
|
|
576
|
-
- 报错 `No Twitter cookies found`:请先登录 `x.com`,并确认浏览器为 Arc/Chrome/Edge/Firefox/Brave
|
|
577
|
-
-
|
|
689
|
+
- 报错 `No Twitter cookies found`:请先登录 `x.com`,并确认浏览器为 Arc/Chrome/Edge/Firefox/Brave/Vivaldi/Zen 之一(或通过 `TWITTER_CHROMIUM_USER_DATA_DIR` 指定目录),或手动设置 `TWITTER_COOKIE_STRING` / `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`。
|
|
690
|
+
- 如需查看浏览器提取细节或环境状态,可加 `-v` 或运行 `twitter doctor`。
|
|
578
691
|
- 报错 `Cookie expired or invalid`:Cookie 过期,重新登录后重试。
|
|
579
692
|
- 报错 `Unable to get key for cookie decryption`(macOS Keychain 问题):
|
|
580
693
|
- **SSH 远程登录**:Keychain 默认锁定,需手动解锁:
|
|
@@ -585,9 +698,15 @@ score = likes_w * likes
|
|
|
585
698
|
- 或在弹出 Keychain 授权时点击 **"始终允许"**。
|
|
586
699
|
- 报错 `Twitter API error 404`:通常是 queryId 轮换,重试即可。
|
|
587
700
|
|
|
701
|
+
- **Windows 下 pipe/subprocess 无法捕获输出**(AI agent 集成场景)
|
|
702
|
+
- 这是 **ConPTY** 伪终端的问题,不是 twitter-cli 的 bug。Windows Terminal 的 ConPTY 可能拦截有网络延迟的命令的管道输出。
|
|
703
|
+
- **解决方案**:使用 **Git Bash** 并在终端设置中设置 `"windowsEnableConpty": false`。
|
|
704
|
+
- ConPTY 关闭后如用 PowerShell,emoji 可能会报 `UnicodeEncodeError: 'gbk'`。Git Bash 原生支持 UTF-8。
|
|
705
|
+
- 标准 `subprocess.run(capture_output=True)` 和文件重定向 (`> file 2>&1`) 不受此问题影响。
|
|
706
|
+
|
|
588
707
|
|
|
589
708
|
|
|
590
|
-
- 结构化错误码通常会区分 `not_authenticated`、`not_found`、`invalid_input`、`rate_limited`、`api_error`。
|
|
709
|
+
- 结构化错误码通常会区分 `not_authenticated`、`not_found`、`invalid_input`、`rate_limited`、`network_error`、`query_id_error`、`media_upload_error`、`api_error`。
|
|
591
710
|
|
|
592
711
|
### 使用建议(防封号)
|
|
593
712
|
|