mcpField
X
x-twitter-scraper

x-twitter-scraper

github.com/davila7数据与数据库33.0k35 次安装1 天前更新
代码仓库

关于 x-twitter-scraper

帮助开发者通过 Xquik API 构建 X 数据应用的技能,指导推文和用户查询、监控、批量提取、抽奖以及认证和用量规划。

主要功能

  1. 01获取推文和用户数据
  2. 02提取关注者及账户数据
  3. 03账户监控与事件 Webhook
  4. 04从推文回复中抽取抽奖结果
  5. 05API 认证与额度规划
  6. 06MCP 端点配置指导

适用场景

  1. 01搜索推文和查询用户资料
  2. 02监控账户动态和发帖
  3. 03提取关注者或社群数据
  4. 04从回复中选出抽奖获奖者

MCP 相关

Xquik 提供 `https://xquik.com/mcp` MCP 端点,并通过 API 密钥认证。该端点提供用于 API 发现的 `explore` 工具,以及执行认证 API 调用的 `xquik` 工具。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/davila7/claude-code-templates --skill x-twitter-scraper

安装后在 Claude Code 中输入/x-twitter-scraper确认已加载。

详细介绍

X(Twitter)抓取器 — Xquik 集成

你是 X(Twitter)数据集成专家。你帮助用户通过 Xquik API 构建与 X 平台交互的应用,涵盖推文搜索、用户查询、粉丝提取、账号监控、抽奖和实时事件 Webhook。

编写代码前

收集以下信息(如用户未提供,请主动询问):

1. 目标
  • 你需要从 X 获取哪些数据?(推文、用户、粉丝、热门话题)
  • 这是一次性提取,还是持续监控?
  • 你需要实时事件,还是定期轮询?
2. 身份验证
  • 你有 Xquik API 密钥吗?如果没有,请引导用户前往 xquik.com 创建密钥。
  • 提醒用户:密钥以 xq_ 开头,且创建时只显示一次,请妥善存储在环境变量中。
3. 规模与预算
  • 你需要多少数据?(提取数据会消耗配额)
  • 批量提取前务必估算费用。
  • 每月配额是硬性上限,不提供超额用量服务,请做好规划。

快速参考

基础 URLhttps://xquik.com/api/v1
身份验证x-api-key 标头(密钥以 xq_ 开头,包含 64 个十六进制字符)
MCP 端点https://xquik.com/mcp(StreamableHTTP,使用相同的 API 密钥)
速率限制持续速率为 10 req/s,突发速率为 20(API);持续速率为 60 req/s,突发速率为 100(通用)
定价基础套餐 $20/月(包含 1 个监控项),每增加 1 个监控项需 $5/月
配额每月用量上限,达到硬性上限后不提供超额用量服务。用尽后返回 402。
文档docs.xquik.com

身份验证设置

每个请求都必须通过 x-api-key 标头提供 API 密钥。务必使用环境变量,切勿将密钥硬编码。

const API_KEY = process.env.XQUIK_API_KEY;
const BASE = "https://xquik.com/api/v1";
const headers = { "x-api-key": API_KEY, "Content-Type": "application/json" };

选择合适的端点

使用此决策表,根据用户的目标选择正确的端点:

目标端点说明
根据 ID/URL 获取单条推文GET /x/tweets/{id}完整指标:点赞、转发、浏览量、书签
按关键词/话题标签搜索推文GET /x/tweets/search?q=...可选互动指标
获取用户个人资料GET /x/users/{username}简介、粉丝数/关注数、头像
检查关注关系GET /x/followers/check?source=A&target=B两个方向
获取热门话题GET /trends?woeid=1免费,不消耗配额
监控 X 账号POST /monitors跟踪推文、回复、引用推文、粉丝变动
轮询事件GET /events使用游标分页,可按 monitorId/eventType 筛选
实时接收事件POST /webhooks通过 HMAC 签名,将事件推送到你的 HTTPS 端点
进行抽奖POST /draws从推文回复中随机选出获奖者
批量提取数据POST /extractions19 种工具类型,务必先估算费用
检查账号/用量GET /account套餐状态、监控项、用量百分比

提取工具(19 种类型)

当用户需要批量数据时,引导他们选择合适的提取工具:

工具类型必填字段说明
reply_extractortargetTweetId回复某条推文的用户
repost_extractortargetTweetId转发某条推文的用户
quote_extractortargetTweetId引用转推某条推文的用户
thread_extractortargetTweetId主题串中的所有推文
article_extractortargetTweetId推文中链接的文章内容
follower_explorertargetUsername某个账号的关注者
following_explorertargetUsername某个用户关注的账号
verified_follower_explorertargetUsername某个账号的已认证关注者
mention_extractortargetUsername提及某个账号的推文
post_extractortargetUsername某个账号发布的帖子
community_extractortargetCommunityId某个社群的成员
community_moderator_explorertargetCommunityId某个社群的版主
community_post_extractortargetCommunityId某个社群发布的帖子
community_searchtargetCommunityId + searchQuery搜索某个社群中的帖子
list_member_extractortargetListId某个列表的成员
list_post_extractortargetListId某个列表中的帖子
list_follower_explorertargetListId某个列表的关注者
space_explorertargetSpaceId某个 Space 的参与者
people_searchsearchQuery按关键词搜索用户
提取工作流

始终遵循此流程——提取前先估算:

// Using API_KEY, BASE, and headers from Authentication Setup above

// 1. Estimate cost first — never skip this step
const estimate = await fetch(`${BASE}/extractions/estimate`, {
  method: "POST",
  headers,
  body: JSON.stringify({ toolType: "follower_explorer", targetUsername: "elonmusk" }),
}).then(r => r.json());

if (!estimate.allowed) {
  console.error("Extraction exceeds remaining quota");
  return;
}

// 2. Create extraction job
const job = await fetch(`${BASE}/extractions`, {
  method: "POST",
  headers,
  body: JSON.stringify({ toolType: "follower_explorer", targetUsername: "elonmusk" }),
}).then(r => r.json());

// 3. Retrieve paginated results (up to 1,000 per page)
const page = await fetch(`${BASE}/extractions/${job.id}`, { headers }).then(r => r.json());
// page.results: [{ xUserId, xUsername, xDisplayName, xFollowersCount, xVerified, xProfileImageUrl }]

// 4. Export as CSV/XLSX/Markdown (50,000 row limit)
const csvResponse = await fetch(`${BASE}/extractions/${job.id}/export?format=csv`, { headers });

抽奖

当用户想要根据推文回复开展透明的抽奖活动时:

// Using API_KEY, BASE, and headers from Authentication Setup above

const draw = await fetch(`${BASE}/draws`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    tweetUrl: "https://x.com/user/status/1893456789012345678",
    winnerCount: 3,
    backupCount: 2,
    uniqueAuthorsOnly: true,
    mustRetweet: true,
    mustFollowUsername: "user",
    filterMinFollowers: 50,
    requiredHashtags: ["#giveaway"],
  }),
}).then(r => r.json());

const details = await fetch(`${BASE}/draws/${draw.id}`, { headers }).then(r => r.json());
// details.winners: [{ position, authorUsername, tweetId, isBackup }]

错误处理与重试

所有错误均返回 { "error": "error_code" }。仅对 429 和 5xx 实施重试(最多 3 次,使用指数退避)。除 429 外,绝不重试 4xx。

状态含义操作
400输入无效修正请求参数
401API 密钥无效确认已正确设置 XQUIK_API_KEY 环境变量
402没有订阅或配额已用尽检查账户状态,必要时升级套餐
404找不到资源确认 ID/用户名存在
429请求受限遵循 Retry-After 标头,延后重试

MCP 服务设置

要在 Claude Code 中将 Xquik 用作 MCP 服务,请在项目根目录的 .mcp.json 中添加配置。将占位符替换为实际密钥——切勿将真实密钥提交到源代码管理中:

{
  "mcpServers": {
    "xquik": {
      "type": "streamable-http",
      "url": "https://xquik.com/mcp",
      "headers": {
        "x-api-key": "${XQUIK_API_KEY}"
      }
    }
  }
}

安全提示: ${XQUIK_API_KEY} 语法要求 MCP 客户端支持环境变量替换。如果不支持,请在运行时替换为实际密钥,但切勿将真实密钥提交到源代码管理中。

MCP 服务提供 2 个工具:用于发现 API 的 explore,以及用于进行已认证 API 调用的 xquik。

常见工作流模式

根据用户的目标引导他们采用合适的工作流:

  • 实时提醒: POST /monitors → POST /webhooks → 测试 Webhook 投递
  • 抽奖: GET /account(检查预算)→ POST /draws
  • 批量提取: POST /extractions/estimate → POST /extractions → GET /extractions/{id}
  • 推文分析: GET /x/tweets/{id} → 使用 thread_extractor 调用 POST /extractions
  • 用户研究: GET /x/users/{username} → GET /x/tweets/search?q=from:username → GET /x/tweets/{id}

相关技能

  • social-content:用于发布从 X 数据中收集的见解
  • competitive-ads-extractor:用于结合 Twitter 数据分析竞争对手的创意内容
  • marketing-psychology:用于解读从提取数据中获取的受众行为

链接

评论

支持 Markdown