x-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

x-api 🐦

x-api 🐦

Post to X using the official API (OAuth 1.0a).
使用基于OAuth 1.0a的X官方API发布内容。

When to Use

使用场景

  • Posting tweets (cookie-based
    bird tweet
    gets blocked by bot detection)
  • Official API access is needed for reliability
For reading (timeline, search, mentions), use
bird
CLI instead — it's free and works well for reads.
  • 发布推文(基于Cookie的
    bird tweet
    会被机器人检测拦截)
  • 需要官方API保障可靠性的场景
如果需要读取内容(时间线、搜索、提及),请改用
bird
CLI——它免费且在读取场景表现出色。

Setup

配置步骤

1. Get API Credentials

1. 获取API凭证

  1. Go to https://developer.x.com/en/portal/dashboard
  2. Create a Project and App
  3. Set App permissions to Read and Write
  4. Get your keys from "Keys and tokens" tab:
    • API Key (Consumer Key)
    • API Key Secret (Consumer Secret)
    • Access Token
    • Access Token Secret
  1. 访问https://developer.x.com/en/portal/dashboard
  2. 创建项目和应用
  3. 将应用权限设置为读写权限
  4. 从“Keys and tokens”标签页获取以下密钥:
    • API Key(Consumer Key)
    • API Key Secret(Consumer Secret)
    • Access Token
    • Access Token Secret

2. Configure Credentials

2. 配置凭证

Option A: Environment variables
bash
export X_API_KEY="your-api-key"
export X_API_SECRET="your-api-secret"
export X_ACCESS_TOKEN="your-access-token"
export X_ACCESS_SECRET="your-access-token-secret"
Option B: Config file at
~/.clawdbot/secrets/x-api.json
json
{
  "consumerKey": "your-api-key",
  "consumerSecret": "your-api-secret",
  "accessToken": "your-access-token",
  "accessTokenSecret": "your-access-token-secret"
}
选项A:环境变量
bash
export X_API_KEY="your-api-key"
export X_API_SECRET="your-api-secret"
export X_ACCESS_TOKEN="your-access-token"
export X_ACCESS_SECRET="your-access-token-secret"
选项B:配置文件 路径为
~/.clawdbot/secrets/x-api.json
json
{
  "consumerKey": "your-api-key",
  "consumerSecret": "your-api-secret",
  "accessToken": "your-access-token",
  "accessTokenSecret": "your-access-token-secret"
}

3. Install Dependency

3. 安装依赖

bash
npm install -g twitter-api-v2
bash
npm install -g twitter-api-v2

Post a Tweet

发布推文

bash
x-post "Your tweet text here"
Or with full path:
bash
node /path/to/skills/x-api/scripts/x-post.mjs "Your tweet text here"
Supports multi-line tweets:
bash
x-post "Line one

Line two

Line three"
Returns the tweet URL on success.
bash
x-post "Your tweet text here"
或使用完整路径:
bash
node /path/to/skills/x-api/scripts/x-post.mjs "Your tweet text here"
支持多行推文:
bash
x-post "Line one

Line two

Line three"
成功发布后会返回推文链接。

Limits

限制说明

  • Free tier: 1,500 posts/month (requires credits in X Developer Portal)
  • Basic tier ($100/mo): Higher limits
  • 免费套餐:每月1500条发布额度(需要在X开发者平台中添加额度)
  • 基础套餐(每月100美元):更高的发布额度

Reading (use bird)

读取内容(使用bird)

For reading, searching, and monitoring — use the
bird
CLI:
bash
bird home                    # Timeline
bird mentions                # Mentions
bird search "query"          # Search
bird user-tweets @handle     # User's posts
bird read <tweet-url>        # Single tweet
如果需要读取、搜索和监控内容,请使用
bird
CLI:
bash
bird home                    # 时间线
bird mentions                # 提及我的内容
bird search "query"          # 搜索
bird user-tweets @handle     # 用户推文
bird read <tweet-url>        # 单条推文详情

Troubleshooting

故障排除

402 Credits Depleted: Add credits in X Developer Portal → Dashboard
401 Unauthorized: Regenerate Access Token (ensure Read+Write permissions are set first)
No credentials found: Set env vars or create config file (see Setup above)
402 额度耗尽:在X开发者平台→控制台中添加额度
401 未授权:重新生成Access Token(确保已先设置读写权限)
未找到凭证:设置环境变量或创建配置文件(见上方配置步骤)