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.
このガイドでは、X API v2 を使って初めてのポスト取得リクエストを行う手順を説明します。
前提条件 開始する前に、次のものが必要です。
承認済みの App を持つ 開発者アカウント
App のベアラートークン (開発者コンソールの「Keys and tokens」で確認できます)
ポストIDを取得する
すべてのポストには一意のIDがあります。ポストのURLに含まれています。 https://x.com/XDevelopers/status/1228393702244134912
└── これがポスト ID です
リクエストを実行
curl "https://api.x.com/2/tweets/1228393702244134912" \
-H "Authorization: Bearer $BEARER_TOKEN "
レスポンスを確認する
デフォルトのレスポンスには、ポストの id、text、edit_history_tweet_ids が含まれます。 {
"data" : {
"id" : "1228393702244134912" ,
"text" : "What did the developer write in their Valentine's card? \n\n while(true) { \n I = Love(You); \n }" ,
"edit_history_tweet_ids" : [ "1228393702244134912" ]
}
}
追加フィールドをリクエストする
クエリパラメータを指定して、より多くのデータを取得します: curl "https://api.x.com/2/tweets/1228393702244134912? \
tweet.fields=created_at,public_metrics,author_id& \
expansions=author_id& \
user.fields=username,verified" \
-H "Authorization: Bearer $BEARER_TOKEN "
レスポンス: {
"data" : {
"id" : "1228393702244134912" ,
"text" : "What did the developer write in their Valentine's card?..." ,
"created_at" : "2020-02-14T19:00:55.000Z" ,
"author_id" : "2244994945" ,
"public_metrics" : {
"retweet_count" : 156 ,
"reply_count" : 23 ,
"like_count" : 892 ,
"quote_count" : 12
},
"edit_history_tweet_ids" : [ "1228393702244134912" ]
},
"includes" : {
"users" : [
{
"id" : "2244994945" ,
"username" : "XDevelopers" ,
"verified" : true
}
]
}
}
複数の投稿を取得する
1 回のリクエストで最大 100 件の投稿を取得する: curl "https://api.x.com/2/tweets? \
ids=1228393702244134912,1227640996038684673,1199786642791452673& \
tweet.fields=created_at,author_id" \
-H "Authorization: Bearer $BEARER_TOKEN "
統合ガイド 認証、レート制限、ベストプラクティスを学ぶ
フィールドとexpansions フィールドとexpansionsシステムをマスターする
APIリファレンス 利用可能なすべてのパラメータを確認する
サンプルコード さらに多くのサンプルコードを確認する