Documentation Index
Fetch the complete documentation index at: https://generaltranslation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
このガイドでは、過去 7 日間の投稿を検索するための recent search リクエストを初めて実行する手順を説明します。
前提条件始める前に、次のものが必要です。
- 承認された App を持つ 開発者アカウント
- 開発者コンソールの「Keys and tokens」で確認できる、App のベアラートークン
クエリを作成
検索クエリでは、投稿を絞り込むためにオペレーターを使用します。まずはシンプルなキーワードから始めましょう:または、複数の演算子を組み合わせます:python lang:en -is:retweet
これは、英語の投稿のうち本文に「python」を含み、リツイートを除外したものに一致します。 リクエストを送信する
curl "https://api.x.com/2/tweets/search/recent?query=python%20lang%3Aen%20-is%3Aretweet" \
-H "Authorization: Bearer $BEARER_TOKEN"
レスポンスを確認する
デフォルトのレスポンスには id、text、edit_history_tweet_ids が含まれます。{
"data": [
{
"id": "1234567890123456789",
"text": "Just started learning Python and loving it!",
"edit_history_tweet_ids": ["1234567890123456789"]
},
{
"id": "1234567890123456788",
"text": "Python tip: use list comprehensions for cleaner code",
"edit_history_tweet_ids": ["1234567890123456788"]
}
],
"meta": {
"newest_id": "1234567890123456789",
"oldest_id": "1234567890123456788",
"result_count": 2
}
}
フィールドとexpansionsを追加する
クエリパラメータを指定して追加のデータをリクエストします:curl "https://api.x.com/2/tweets/search/recent?\
query=python%20lang%3Aen%20-is%3Aretweet&\
tweet.fields=created_at,public_metrics,author_id&\
expansions=author_id&\
user.fields=username,verified&\
max_results=10" \
-H "Authorization: Bearer $BEARER_TOKEN"
レスポンス:{
"data": [
{
"id": "1234567890123456789",
"text": "Just started learning Python and loving it!",
"created_at": "2024-01-15T10:30:00.000Z",
"author_id": "9876543210",
"public_metrics": {
"retweet_count": 5,
"reply_count": 2,
"like_count": 42,
"quote_count": 1
},
"edit_history_tweet_ids": ["1234567890123456789"]
}
],
"includes": {
"users": [
{
"id": "9876543210",
"username": "pythondev",
"verified": false
}
]
},
"meta": {
"newest_id": "1234567890123456789",
"oldest_id": "1234567890123456789",
"result_count": 1
}
}
結果をページングする
SDK はページネーションを自動処理します。cURL を使用する場合は、レスポンスの next_token を使用してください。curl "https://api.x.com/2/tweets/search/recent?\
query=python&\
max_results=100&\
next_token=b26v89c19zqg8o3fo7gesq314yb9l2l4ptqy" \
-H "Authorization: Bearer $BEARER_TOKEN"
ページネーションガイド
大規模な結果セットの扱い方について詳しく学ぶ
"machine learning" has:images lang:en
@elonmusk -is:retweet -is:reply
クエリを作成する
クエリ構文とオペレーターをマスターする
オペレーターリファレンス
利用可能なすべてのオペレーターを確認する
APIリファレンス
エンドポイントの詳細ドキュメント