← 返回
开发者工具 Key 中文

X Apify

Fetch X/Twitter data via Apify actors. Search tweets, get user profiles, retrieve specific tweets with replies. Features local caching to save API costs. Wor...
通过Apify获取X/Twitter数据。支持搜索推文、获取用户资料及检索带回复的特定推文。具备本地缓存功能以节省API成本。
robbyczgw-cla
开发者工具 clawhub v1.0.8 3 版本 99671.5 Key: 需要
★ 0
Stars
📥 1,517
下载
💾 13
安装
3
版本
#latest

概述

x-apify

Fetch X/Twitter data via Apify API (search tweets, user profiles, specific tweets).

Why Apify?

X/Twitter's official API is expensive and restrictive. Apify provides reliable access to public tweet data through its actor ecosystem, with residential proxy support.

Free Tier

  • $5/month free credits (no credit card required)
  • Cost varies by actor usage
  • Perfect for personal use

Links

Setup

  1. Create free Apify account: https://apify.com/
  2. Get your API token: https://console.apify.com/account/integrations
  3. Set environment variable:
# Add to ~/.bashrc or ~/.zshrc
export APIFY_API_TOKEN="apify_api_YOUR_TOKEN_HERE"

# Or use .env file (never commit this!)
echo 'APIFY_API_TOKEN=apify_api_YOUR_TOKEN_HERE' >> .env

Usage

Search Tweets

# Search for tweets containing keywords
python3 scripts/fetch_tweets.py --search "artificial intelligence"

# Search with hashtags
python3 scripts/fetch_tweets.py --search "#AI #MachineLearning"

# Limit results
python3 scripts/fetch_tweets.py --search "OpenAI" --max-results 10

User Profiles

# Get tweets from a specific user
python3 scripts/fetch_tweets.py --user "elonmusk"

# Multiple users (comma-separated)
python3 scripts/fetch_tweets.py --user "OpenAI,AnthropicAI"

Specific Tweet

# Get a specific tweet and its replies
python3 scripts/fetch_tweets.py --url "https://x.com/user/status/123456789"

# Also works with twitter.com URLs
python3 scripts/fetch_tweets.py --url "https://twitter.com/user/status/123456789"

Output Formats

# JSON output (default)
python3 scripts/fetch_tweets.py --search "query" --format json

# Summary format (human-readable)
python3 scripts/fetch_tweets.py --search "query" --format summary

# Save to file
python3 scripts/fetch_tweets.py --search "query" --output results.json

Caching

Tweets are cached locally by default to save API costs.

# First request: fetches from Apify (costs credits)
python3 scripts/fetch_tweets.py --search "query"

# Second request: uses cache (FREE!)
python3 scripts/fetch_tweets.py --search "query"
# Output: [cached] Results for: query

# Bypass cache (force fresh fetch)
python3 scripts/fetch_tweets.py --search "query" --no-cache

# View cache stats
python3 scripts/fetch_tweets.py --cache-stats

# Clear all cached results
python3 scripts/fetch_tweets.py --clear-cache

Cache TTL:

  • Search results: 1 hour
  • User profiles: 24 hours
  • Specific tweets: 24 hours

Cache location: .cache/ in skill directory (override with X_APIFY_CACHE_DIR env var)

Output Examples

JSON Format

{
  "query": "OpenAI",
  "mode": "search",
  "fetched_at": "2026-02-11T10:30:00Z",
  "count": 20,
  "tweets": [
    {
      "id": "1234567890",
      "text": "OpenAI just announced...",
      "author": "techreporter",
      "author_name": "Tech Reporter",
      "created_at": "2026-02-11T09:00:00Z",
      "likes": 1500,
      "retweets": 300,
      "replies": 50,
      "url": "https://x.com/techreporter/status/1234567890"
    }
  ]
}

Summary Format

=== X/Twitter Search Results ===
Query: OpenAI
Fetched: 2026-02-11 10:30:00 UTC
Results: 20 tweets

---
@techreporter (Tech Reporter)
2026-02-11 09:00
OpenAI just announced...
[Likes: 1500 | RTs: 300 | Replies: 50]
https://x.com/techreporter/status/1234567890

---
...

Error Handling

The script handles common errors:

  • Invalid search query
  • User not found
  • Tweet not found
  • API quota exceeded
  • Network errors

Metadata

metadata:
  openclaw:
    emoji: "X"
    requires:
      env:
        APIFY_API_TOKEN: required
        APIFY_ACTOR_ID: optional
        X_APIFY_CACHE_DIR: optional
      bins:
        - python3

版本历史

共 3 个版本

  • v1.0.8 当前
    2026-03-28 22:43 安全 安全
  • v1.0.6
    2026-03-11 09:38
  • v1.0.3
    2026-03-07 11:47

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,763
ai-intelligence

Personas

robbyczgw-cla
可按需转换为20种专业AI人格,支持对话中切换,仅加载当前人格。
★ 31 📥 12,168
developer-tools

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 668 📥 323,946