認証
| 方法 | 推奨用途 | 非公開リストへのアクセスは可能ですか? |
|---|---|---|
| OAuth 2.0 App-Only | 公開リストのデータ | いいえ |
| OAuth 2.0 Authorization Code with PKCE | ユーザー向け App | はい (所有/フォロー中) |
| OAuth 1.0a User Context | レガシーな統合 | はい (所有/フォロー中) |
リクエスト例
cURL
curl "https://api.x.com/2/lists/84839422?\
list.fields=description,member_count,follower_count,private" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# リスト ID を指定してリストを取得
response = client.lists.get(
list_id="84839422",
list_fields=["description", "member_count", "follower_count", "private"]
)
print(response.data)
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
const response = await client.lists.get("84839422", {
listFields: ["description", "member_count", "follower_count", "private"],
});
console.log(response.data);
エンドポイント概要
| メソッド | エンドポイント | 説明 |
|---|---|---|
| GET | /2/lists/:id | ID で指定したリストを取得 |
| GET | /2/users/:id/owned_lists | 指定ユーザーが所有するリストを取得 |
フィールドとexpansions
既定のレスポンス
{
"data": {
"id": "84839422",
"name": "Tech News"
}
}
利用可能なフィールド
list.fields
list.fields
| フィールド | 説明 |
|---|---|
created_at | リストが作成された日時 |
description | リストの説明 |
follower_count | フォロワー数 |
member_count | メンバー数 |
owner_id | オーナーのユーザーID |
private | リストが非公開かどうか |
user.fields (owner_id の展開が必要)
user.fields (owner_id の展開が必要)
| フィールド | 説明 |
|---|---|
username | オーナーの @handle |
name | オーナーの表示名 |
verified | オーナーの認証ステータス |
profile_image_url | オーナーのプロフィール画像の URL |
expansions を利用した例
cURL
curl "https://api.x.com/2/lists/84839422?\
list.fields=description,member_count,follower_count,owner_id&\
expansions=owner_id&\
user.fields=username,verified" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# 所有者の expansion を指定してリストを取得
response = client.lists.get(
list_id="84839422",
list_fields=["description", "member_count", "follower_count", "owner_id"],
expansions=["owner_id"],
user_fields=["username", "verified"]
)
print(response.data)
print(response.includes) # 所有者のユーザーオブジェクトが含まれる
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
const response = await client.lists.get("84839422", {
listFields: ["description", "member_count", "follower_count", "owner_id"],
expansions: ["owner_id"],
userFields: ["username", "verified"],
});
console.log(response.data);
console.log(response.includes); // 所有者のユーザーオブジェクトが含まれる
expansions を含むレスポンス
{
"data": {
"id": "84839422",
"name": "Tech News",
"description": "Top tech journalists",
"member_count": 50,
"follower_count": 1250,
"owner_id": "2244994945"
},
"includes": {
"users": [
{
"id": "2244994945",
"username": "XDevelopers",
"verified": true
}
]
}
}
Fields と expansions のガイド
レスポンスのカスタマイズ方法について詳しく学びましょう
ページネーション
cURL
# 最初のリクエスト
curl "https://api.x.com/2/users/123/owned_lists?max_results=100" \
-H "Authorization: Bearer $BEARER_TOKEN"
# ページネーショントークンを指定した後続リクエスト
curl "https://api.x.com/2/users/123/owned_lists?max_results=100&pagination_token=NEXT_TOKEN" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# SDK がページネーションを自動的に処理します
all_lists = []
for page in client.lists.get_user_owned_lists(user_id="123", max_results=100):
if page.data:
all_lists.extend(page.data)
print(f"{len(all_lists)} 個のリストが見つかりました")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
async function getAllOwnedLists(userId) {
const allLists = [];
// SDK がページネーションを自動的に処理します
const paginator = client.lists.getUserOwnedLists(userId, { maxResults: 100 });
for await (const page of paginator) {
if (page.data) {
allLists.push(...page.data);
}
}
return allLists;
}
// 使用例
const lists = await getAllOwnedLists("123");
console.log(`合計 ${lists.length} 個のリストが見つかりました`);
ページネーションガイド
ページネーションの詳細はこちら
非公開リスト
- 非公開リストは、所有者にのみ表示されます
- 非公開リストの詳細を取得するには、所有者として認証されている必要があります
privateフィールドは、リストが非公開かどうかを示します
エラー処理
| ステータス | エラー | 解決策 |
|---|---|---|
| 400 | 無効なリクエスト | リスト ID の形式を確認してください |
| 401 | 認証されていません | 認証情報を確認してください |
| 403 | アクセスが禁止されています | リストが非公開である可能性があります |
| 404 | 見つかりません | リストが存在しません |
| 429 | リクエストが多すぎます | 待機してから再試行してください |
次のステップ
クイックスタート
最初のリスト検索リクエストを行う
リストの投稿
リストから投稿を取得する
APIリファレンス
エンドポイントの完全なドキュメント
Sample code
動作するコード例