---
title: "Zapier"
description: "通过 TwexAPI 构建 Zapier Twitter 自动化，实现推文搜索、用户查询、热门推文、平台 webhook 与游标安全 handoff。"
---

用 TwexAPI 构建 Zapier Twitter 自动化。搜索推文、查询用户、读取热门推文，并将行路由到 Slack、Sheets、Airtable、HubSpot 或邮件。TwexAPI 使用单一 API 密钥与 REST 基址 `https://api.twexapi.io`。

## 选择 Zapier 集成模式

<CardGroup cols={2}>
  <Card title="Community node + MCP agent" icon="bot">
    具备 MCP 的AI Agent负责发现，再将严格 JSON POST 到 Zapier Catch Hook。
  </Card>

  <Card title="自定义 HTTP 请求动作" icon="link">
    从 Webhooks by Zapier 或私有集成直接调用 TwexAPI REST。
  </Card>

  <Card title="n8n 风格社区专属节点" icon="plug">
    团队已用 n8n 时优先专用 [n8n 社区节点](/guides/n8n)。
  </Card>
</CardGroup>

原生 Zapier X 应用已下线。TwexAPI 仍可通过 Catch Hooks、HTTP Request 或私有 Zapier 应用使用。

## 前置条件

* [TwexAPI API 密钥](https://twexapi.io/dashboard)
* 含 Webhooks by Zapier 的 Zapier 账号
* 可选 Slack、Google Sheets、Airtable、HubSpot 或 Gmail 目标
* 可选：已连接 `https://api.twexapi.io/mcp` 的 MCP capable AI Agent

## API 密钥认证

为 TwexAPI REST 调用创建可复用凭证：

<CardGroup cols={3}>
  <Card title="身份认证与鉴权" icon="key-round">
    在 HTTP Request 中选择 Header Auth 或自定义 header。
  </Card>

  <Card title="请求头名称" icon="braces">
    Header 名称设为 `Authorization`。
  </Card>

  <Card title="请求头数值" icon="shield-check">
    凭证值粘贴 `Bearer YOUR_API_KEY`。
  </Card>
</CardGroup>

Zapier 外的 MCP capable AI Agent 步骤：配置 `https://api.twexapi.io/mcp`，header `x-api-key: YOUR_API_KEY`。

## 集成形状

1. **创建 Catch Hook 接收端点**

    使用 Webhooks by Zapier，AI Agent handoff 或外部 POST 选 Catch Hook。

2. **提取 TwexAPI 数据记录**

    用 MCP、HTTP Request 或外部 worker 产出严格 JSON。

3. **映射规范字段**

    以 `tweet_id` 为去重键。映射文本、作者、URL 与游标字段。

4. **路由分发至下游系统**

    将行发送到 Slack、Sheets、Airtable、HubSpot 或邮件。

## 入门操作

HTTP Request 或私有 Zapier 应用可用于这些常见读取：

<CardGroup cols={2}>
  <Card title="搜索推文" icon="search">
    `POST /twitter/advanced_search/page`，含 `searchTerms`、`sortBy`、`nextCursor`。
  </Card>

  <Card title="获取用户资料" icon="user-round">
    `GET /twitter/{screen_name}/about`
  </Card>

  <Card title="搜索 Twitter 用户" icon="users">
    `GET /twitter/search-user/{keyword}/{target_count}`
  </Card>

  <Card title="获取热门趋势" icon="trending-up">
    `GET /twitter/global-trending/tweets`，含国家、主题与内容筛选。
  </Card>

  <Card title="获取粉丝列表" icon="users">
    `POST /v3/twitter/users/followers`，含用户名与游标分页。
  </Card>

  <Card title="发布推文" icon="send">
    人工审批与 cookie 设置后 `POST /twitter/tweets/create`。
  </Card>
</CardGroup>

### HTTP Request 示例：搜索推文

```json
{
  "method": "POST",
  "url": "https://api.twexapi.io/twitter/advanced_search/page",
  "headers": {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  "body": {
    "searchTerms": ["AI agents lang:en"],
    "sortBy": "Latest",
    "nextCursor": ""
  }
}
```

## 结果 handoff

下一 Zap 步骤仅需稳定 handoff 字段时使用 Formatter 或 Code 步骤。

<CardGroup cols={2}>
  <Card title="推文搜索分页" icon="search">
    存储查询；每条推文 `id` 映射为 `tweet_id`，外加 `text`、作者用户名、`created_at`；保留 `has_next_page` 与 `next_cursor`。
  </Card>

  <Card title="用户画像记录" icon="users">
    源 `id` 存为 `user_id`，外加 `username`、`name`、粉丝数与查询输入。
  </Card>

  <Card title="趋势话题榜单" icon="trending-up">
    存储国家、主题、内容标签与推文行及工作流运行元数据。
  </Card>

  <Card title="发推或回复写入" icon="send">
    从 Zapier 发帖前用 [CLI](/sdks/cli) `--dry-run` 预览。写操作需 cookie 或 `auth_token`。
  </Card>
</CardGroup>

## 配方 1：MCP AI Agent研究到 Slack

建议 MCP AI Agent prompt：

```text
Find recent posts about AI agents in fintech, group them by theme, and list 5 accounts worth monitoring.
Return only JSON with route_used, tweets, has_more, and next_cursor.
Each tweet must include tweet_id, author_username, text, created_at, and public_url.
Do not call write endpoints.
```

Zap 步骤：

1. Catch Hook 接收 JSON 载荷。
2. 循环或 line-item 遍历 `tweets`。
3. 过滤空行。
4. Slack 消息含作者、文本与 URL。

## 配方 2：定时推文搜索到 Google Sheets

1. 每日或每小时 Schedule Zap。
2. HTTP Request 调用 `POST /twitter/advanced_search/page`。
3. 循环返回推文。
4. 向 Sheets 追加 `tweet_id`、作者、文本、`created_at` 与构建的 URL。
5. 若后续 Zap 需继续分页，在 Storage by Zapier 存储 `next_cursor`。

## 配方 3：热门推文告警

```json
{
  "method": "GET",
  "url": "https://api.twexapi.io/twitter/global-trending/tweets",
  "headers": {
    "Authorization": "Bearer YOUR_API_KEY"
  },
  "query": {
    "country": "United States",
    "topic": "Sports",
    "content": "NFL",
    "count": 20
  }
}
```

按互动过滤后将摘要文本路由到 Slack 或邮件。

## 错误处理

| 状态 | Zap 行为 |
| ------ | ------------ |
| `400` | 停止并修正请求映射。 |
| `401` | 失败 Zap 并告警运维更换 API 密钥。 |
| `403` | 暂停直至账号访问或额度恢复。 |
| `429` | 延迟并用 Zapier 内置 replay 重试。 |
| `5xx` | 谨慎重试；保留游标。 |

## 私有集成蓝图

将 TwexAPI 打包为私有 Zapier 集成时，从小而可靠的面开始：

| 资源 | 操作 |
| --- | --- |
| Tweets | 搜索推文、推文详情、审批后发帖 |
| Users | 获取用户、搜索用户 |
| Trends | 获取全球热门推文 |
| Followers | 获取 followers v3 页 |

打包操作用 REST，AI Agent驱动发现工作流用 MCP。

## 测试清单

* 用真实 TwexAPI handoff 载荷测试 Catch Hook。
* 确认每个 REST 请求含 `Authorization: Bearer YOUR_API_KEY`。
* 写入目标应用前以 `tweet_id` 为去重键。
* 在 Storage by Zapier 存储 `next_cursor` 供后续 Zap。
* 人工批准最终文本前写操作保持草稿。

## 下一步

* 团队偏好 TwexAPI 社区节点时用 [n8n](/guides/n8n)
* 可视化场景路由用 [Make](/guides/make)
* [Agent MCP Handoff](/mcp/agent-handoff)
* [Advanced Twitter Search](/api-reference/search-endpoints/get-data-page-twitter-advanced-search-page-post)
