---
title: "CLI"
description: "使用 TwexAPI CLI 进行推文搜索、粉丝导出、私信、X Articles 与终端 X API 自动化。"
---

当你需要确定性的终端命令、JSON 输出、dry-run 预览与已保存的凭证 profile，且无需编写应用代码即可完成 TwexAPI REST 工作流时，请使用 CLI。

| CLI 任务 | 命令 | 保存 |
| -------- | ------------------------ | ------------ |
| 搜索推文 | `x-api-scraper search tweets` | cursor |
| 读取资料 | `x-api-scraper about` | `screen_name` |
| 列出粉丝 | `x-api-scraper followers` | cursor |

## 安装

```bash
npm install -g @twexapi-dev/x-api-scraper-cli
x-api-scraper --help
```

需要 Node.js 18 或更高版本。

源码：[twexapi-dev/x-api-scraper-cli](https://github.com/twexapi-dev/x-api-scraper-cli)

## 认证

从 [TwexAPI dashboard](https://twexapi.io/dashboard) 获取 API 密钥。

```bash
export X_API_SCRAPER_KEY="YOUR_API_KEY"

x-api-scraper auth apps add --name prod --api-key "YOUR_API_KEY"
x-api-scraper auth apps use prod
x-api-scraper --app prod about elonmusk
```

## 基础示例

```bash
# Lookup users
x-api-scraper --app prod users elonmusk sama

# Search tweets
x-api-scraper --app prod search tweets "founder" "ai" --sort Latest

# List followers (v3)
x-api-scraper --app prod followers elonmusk

# Global trending tweets
x-api-scraper --app prod trending tweets --country "United States" --topic "Sports" --count 50
```

## 原始 API 请求

直接调用任意 TwexAPI 路径：

```bash
x-api-scraper --app prod /twitter/elonmusk/about
x-api-scraper --app prod -X POST -d '["elonmusk","sama"]' /twitter/users
```

## 作为 Skill 使用

从 GitHub skill 安装器安装：

```bash
npx skills add twexapi-dev/x-api-scraper-cli
```

或从 ClawHub 安装：

```bash
npx clawhub@latest install x-api-scraper-cli
```

## 安全说明

- CLI 从环境变量读取 `X_API_SCRAPER_KEY`、`X_API_SCRAPER_BASE_URL` 与 `X_API_SCRAPER_CONFIG_DIR`。
- 默认情况下，已保存的 app 配置与 profile 以纯 JSON 存储在 `~/.x-api-scraper/config.json`。
- 在 Agent 工作流中，任何写操作前请先使用 `--dry-run`。

## 参考

* [SDK 概览](/sdks)
* [认证](/authentication)
* [MCP 服务器](/mcp/overview)
* [Agent MCP 交接](/mcp/agent-handoff)
* [高级 Twitter 搜索](/api-reference/search-endpoints/get-data-page-twitter-advanced-search-page-post)
* [源码仓库](https://github.com/twexapi-dev/x-api-scraper-cli)
