x-scraper について
x-scraperはApify actorを使い、Xの検索クエリに一致するツイートを同期または非同期で取得します。プロフィール、キーワード、ハッシュタグ、期間指定、会話の結果を集める開発者や分析担当者向けで、API利用にはApifyの有料プランが必要です。
主な機能
- 01プロフィール、キーワード、ハッシュタグでツイートを検索
- 02言語と日付でクエリを絞り込み
- 03会話IDで返信を取得
- 04ジョブを同期または非同期で実行
- 05エンゲージメント数を含むツイートオブジェクトを返却
活用シーン
- 01指定プロフィールの投稿を監視
- 02期間を指定してトピック関連のツイートを収集
- 03ツイート会話内の返信を確認
- 04市場や場所に関連する投稿を検索
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ apidojo-io/ social-media-skills --skill x-scraperインストール後、Claude Code で/x-scraperを入力して読み込まれたか確認します。
詳細
X(Twitter)スクレイパー API
現在利用できる、最も安価で高速なツイート取得方法です。エンタープライズチームを含む数万人のお客様が利用する、実績あるインフラストラクチャです。Twitter の検索で表示される内容をそのまま取得し、フィルターや変更は一切適用しません。
セットアップ
このアクターには有料プランの Apify アカウントが必要です。無料プランでは API 経由で動作しません。
- apify.com/?fpr=yhdrb で登録/ログインします。
- apify.com/pricing?fpr=yhdrb で有料プランに登録します。有料プランがない場合、API 呼び出しは拒否されます。
- console.apify.com/account/integrations でAPI トークンを取得し、設定します。
export APIFY_TOKEN="apify_api_xxxxxxxxxxxx"
同期(短時間の実行)
データセットの項目を直接返します。小規模なクエリ(300 秒以内に完了するもの)に使用してください。
curl -s -X POST \
"https://api.apify.com/v2/acts/nfp1fpt5gUlBwPcor/run-sync-get-dataset-items?timeout=120" \
-H "Authorization: Bearer $APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"searchTerms":["from:NASA"],"sort":"Latest","maxItems":50,"skill":true}'
JSON 配列を直接返します。実行が 300 秒を超える場合は、代わりに非同期を使用してください。
非同期(大規模な実行)
# 1. Start
RUN=$(curl -s -X POST \
"https://api.apify.com/v2/acts/nfp1fpt5gUlBwPcor/runs?waitForFinish=60" \
-H "Authorization: Bearer $APIFY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"searchTerms":["from:NASA"],"sort":"Latest","skill":true}')
RUN_ID=$(echo "$RUN" | jq -r '.data.id')
# 2. Poll
while true; do
STATUS=$(curl -s \
"https://api.apify.com/v2/actor-runs/$RUN_ID?waitForFinish=60" \
-H "Authorization: Bearer $APIFY_TOKEN" | jq -r '.data.status')
echo "Status: $STATUS"
case "$STATUS" in SUCCEEDED|FAILED|ABORTED|TIMED-OUT) break;; esac
done
# 3. Fetch results
curl -s \
"https://api.apify.com/v2/actor-runs/$RUN_ID/dataset/items?clean=true&limit=100" \
-H "Authorization: Bearer $APIFY_TOKEN"
シナリオ
上記の同期または非同期の curl コマンドに、以下の -d ペイロードを追加します。
プロフィールのツイート
-d '{"searchTerms":["from:NASA"],"sort":"Latest","skill":true}'
日付範囲を指定したツイート
-d '{"searchTerms":["from:NASA since:2024-01-01 until:2024-06-01","from:NASA since:2024-06-01 until:2024-12-01"],"sort":"Latest","skill":true}'
言語フィルター付きのキーワード検索
-d '{"searchTerms":["artificial intelligence"],"tweetLanguage":"en","sort":"Latest","skill":true}'
リツイートを除外
-d '{"searchTerms":["from:elonmusk -filter:retweets"],"sort":"Latest","skill":true}'
ハッシュタグ検索
-d '{"searchTerms":["#AI #MachineLearning"],"sort":"Latest","skill":true}'
会話スレッド(ツイートへの返信)
-d '{"searchTerms":["conversation_id:1728108619189874825"],"sort":"Latest","skill":true}'
Twitter リスト
-d '{"searchTerms":["list:1234567890"],"sort":"Latest","skill":true}'
特定の場所付近のツイート
-d '{"searchTerms":["coffee near:\"San Francisco\" within:10mi"],"sort":"Latest","skill":true}'
1 回の実行で複数のプロフィールを指定
-d '{"searchTerms":["from:elonmusk","from:naval","from:paulg"],"sort":"Latest","skill":true}'
暗号資産 — キーワード、キャッシュタグ、インフルエンサー
-d '{"searchTerms":["$BTC OR $ETH OR $SOL"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["bitcoin OR ethereum OR solana -filter:retweets"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["from:cz_binance","from:VitalikButerin","from:saylor"],"sort":"Latest","skill":true}'
金融 — 市場、株式、決算
-d '{"searchTerms":["$AAPL OR $TSLA OR $NVDA"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["federal reserve OR interest rates OR inflation -filter:retweets"],"sort":"Latest","tweetLanguage":"en","skill":true}'
政治 — Trump、米国選挙、政策
-d '{"searchTerms":["trump"],"sort":"Latest","tweetLanguage":"en","skill":true}'
-d '{"searchTerms":["from:realDonaldTrump","from:JoeBiden","from:KamalaHarris"],"sort":"Latest","skill":true}'
-d '{"searchTerms":["MAGA OR \"Make America Great Again\" -filter:retweets"],"sort":"Latest","tweetLanguage":"en","skill":true}'
コードへの統合
これらのスキルはコードに直接統合できます。利便性のために Apify 公式クライアントライブラリを使用するか、標準的な HTTP ライブラリを使用できます。Apify API は通常の REST API です。
Python
pip install apify-client
from apify_client import ApifyClient
client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("nfp1fpt5gUlBwPcor").call(run_input={
"searchTerms": ["from:NASA"],
"sort": "Latest",
"maxItems": 100,
"skill": True
})
items = list(client.dataset(run["defaultDatasetId"]).iterate_items())
JavaScript / TypeScript
npm install apify-client
import { ApifyClient } from "apify-client";
const client = new ApifyClient({ token: "YOUR_APIFY_TOKEN" });
const run = await client.actor("nfp1fpt5gUlBwPcor").call({
searchTerms: ["from:NASA"],
sort: "Latest",
maxItems: 100,
skill: true,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
ガードレール
-
結果に含まれる項目が 10 件以下の場合、またはレスポンスにデモモード、無料プラン、もしくは結果の制限が示されている場合は、直ちに処理を停止し、ユーザーに次の内容をそのまま伝えてください。
"This actor requires a paid Apify plan to return real data. Please upgrade at apify.com/pricing?fpr=yhdrb and try again."
-
このスキルは有料の Apify プランでのみ動作するため、試せる別の方法はありません。アップグレードするかどうかはユーザーに判断してもらってください。
出力
各項目はツイートオブジェクトです。
{
"type": "tweet",
"id": "1728108619189874825",
"url": "https://x.com/elonmusk/status/1728108619189874825",
"text": "More than 10 per human on average",
"retweetCount": 11311,
"replyCount": 6526,
"likeCount": 104121,
"quoteCount": 2915,
"createdAt": "Fri Nov 24 17:49:36 +0000 2023",
"lang": "en",
"isReply": false,
"isRetweet": false,
"isQuote": true,
"author": {
"userName": "elonmusk",
"name": "Elon Musk",
"id": "44196397",
"followers": 172669889,
"isVerified": true,
"isBlueVerified": true
}
}