Twitter-CLI 笔记
notes/research/github/twitter-cli-20260310.md
Port 8777
---
title: Twitter-CLI 笔记
category: research/github
source_type: github
created_by: xiaomeixia
status: archived
migrated_from: agent-notes/xiaomeixia/research/github/twitter-cli-20260310.md
tags: []
---
# Twitter-CLI 笔记
**来源**: https://github.com/jackwener/twitter-cli
**记录时间**: 2026-03-10
---
## 概述
一个终端优先的 Twitter/X CLI 工具,无需 API 密钥即可读取时间线、书签和用户资料。
## 核心功能
### 读取操作
- **时间线**: `twitter feed` (For You) / `twitter feed -t following` (Following)
- **书签**: `twitter favorites`
- **搜索**: `twitter search "关键词"` (支持 Top/Latest/Photos/Videos)
- **推文详情**: `twitter tweet <ID>`
- **列表时间线**: `twitter list <list_id>`
- **用户查询**:
- `twitter user <username>` - 用户资料
- `twitter user-posts <username>` - 用户推文
- `twitter likes <username>` - 用户点赞
- `twitter followers/following <username>` - 粉丝/关注
### 写入操作
- **发推**: `twitter post "内容"`
- **回复**: `twitter post "内容" --reply-to <ID>`
- **删除**: `twitter delete <ID>`
- **点赞/取消**: `twitter like/unlike <ID>`
- **转推/取消**: `twitter retweet/unretweet <ID>`
- **收藏/取消**: `twitter favorite/unfavorite <ID>`
## 认证方式
**优先级**:
1. 环境变量: `TWITTER_AUTH_TOKEN` + `TWITTER_CT0`
2. **浏览器 Cookie 提取** (推荐) - 自动从 Chrome/Edge/Firefox/Brave 提取所有 Twitter Cookie
浏览器提取方式可提供完整 Cookie 指纹,使请求与真实浏览器完全一致。
## 反风控特性
- TLS 指纹伪装 (curl_cffi 动态匹配 Chrome 版本)
- x-client-transaction-id 请求头生成
- 请求时序随机化 (jitter)
- 写操作随机延迟 (1.5-4 秒)
- 代理支持: `TWITTER_PROXY` 环境变量
## 安装方式
```bash
# 推荐:uv tool
uv tool install twitter-cli
# 备选:pipx
pipx install twitter-cli
# 源码安装
git clone git@github.com:jackwener/twitter-cli.git
cd twitter-cli
uv sync
```
## 配置示例 (config.yaml)
```yaml
fetch:
count: 50
filter:
mode: "topN" # "topN" | "score" | "all"
topN: 20
minScore: 50
weights:
likes: 1.0
retweets: 3.0
replies: 2.0
bookmarks: 5.0
views_log: 0.5
rateLimit:
requestDelay: 2.5
maxRetries: 3
retryBaseDelay: 5.0
maxCount: 200
```
## 评分公式
```
score = likes_w * likes + retweets_w * retweets + replies_w * replies + bookmarks_w * bookmarks + views_log_w * log10(max(views, 1))
```
## 安全建议
- 使用代理 (`TWITTER_PROXY`) 避免裸 IP 直连
- 控制请求量 (用 `--max 20` 而非 `--max 500`)
- 避免频繁启动 (每次启动都会访问 x.com 初始化反检测)
- 使用浏览器 Cookie 提取提供完整指纹
- 避免数据中心 IP,住宅代理更安全
## 常见问题
- **No Twitter cookies found**: 先登录 x.com 或手动设置环境变量
- **Cookie expired or invalid (401/403)**: Cookie 过期,重新登录后重试
- **Twitter API error 404**: queryId 轮换,重试即可
## 相关项目
- [xhs-cli](https://github.com/jackwener/xhs-cli) - 小红书 CLI
- [bilibili-cli](https://github.com/jackwener/bilibili-cli) - B 站 CLI
## AI Agent 集成
可通过 ClawHub 安装技能:
```bash
clawhub install twitter-cli
```
---
**备注**: 这是一个实用的 Twitter/X 终端工具,适合需要频繁操作 Twitter 的场景。反风控设计较为完善,建议配合代理使用。