認証
List lookup エンドポイントは複数の認証方式をサポートします:| Method | Best for | 非公開 List にアクセスできるか |
|---|---|---|
| OAuth 2.0 App-Only | 公開 List データ | 不可 |
| OAuth 2.0 Authorization Code with PKCE | ユーザー向けアプリ | 可 (所有/フォロー中) |
| 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 で List を取得
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);
エンドポイントの概要
| Method | Endpoint | Description |
|---|---|---|
| GET | /2/lists/:id | ID で List を取得 |
| GET | /2/users/:id/owned_lists | ユーザーが所有する List を取得 |
Fields と expansions
デフォルトのレスポンス
{
"data": {
"id": "84839422",
"name": "Tech News"
}
}
利用可能なフィールド
list.fields
list.fields
| Field | Description |
|---|---|
created_at | List 作成のタイムスタンプ |
description | List の説明 |
follower_count | フォロワー数 |
member_count | メンバー数 |
owner_id | 所有者の user ID |
private | List が非公開かどうか |
user.fields (owner_id expansion が必要)
user.fields (owner_id expansion が必要)
| Field | Description |
|---|---|
username | 所有者の @ハンドル |
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 付きで List を取得
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); // 所有者のユーザーオブジェクトが含まれます
expansion 付きのレスポンス
{
"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 ガイド
レスポンスのカスタマイズについて詳しく学ぶ
ページネーション
所有 List の取得時、結果はページネーションされます:cURL
# 最初のリクエスト
curl "https://api.x.com/2/users/123/owned_lists?max_results=100" \
-H "Authorization: Bearer $BEARER_TOKEN"
# pagination_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"Found {len(all_lists)} 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(`Found ${lists.length} lists`);
ページネーションガイド
ページネーションについて詳しく学ぶ
非公開 List
- 非公開 List は所有者にのみ表示されます
- 非公開 List の詳細を取得するには、所有者として認証する必要があります
privateフィールドは、その List が非公開かどうかを示します
エラー処理
| Status | Error | Solution |
|---|---|---|
| 400 | Invalid request | List ID の形式を確認 |
| 401 | Unauthorized | 認証を確認 |
| 403 | Forbidden | 非公開の List の可能性 |
| 404 | Not Found | List が存在しない |
| 429 | Too Many Requests | 待機してから再試行 |
次のステップ
クイックスタート
最初の List lookup リクエストを行う
List Posts
List から Post を取得
API リファレンス
エンドポイントの詳細ドキュメント
サンプルコード
動作するコード例