ID でリストを取得する
cURL
curl "https://api.x.com/2/lists/1234567890?\
list.fields=description,owner_id,member_count,follower_count,private,created_at" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# ID でリストを取得する
response = client.lists.get(
"1234567890",
list_fields=["description", "owner_id", "member_count", "follower_count", "private", "created_at"]
)
print(f"List: {response.data.name}")
print(f"Members: {response.data.member_count}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// ID でリストを取得する
const response = await client.lists.get("1234567890", {
listFields: ["description", "owner_id", "member_count", "follower_count", "private", "created_at"],
});
console.log(`List: ${response.data?.name}`);
console.log(`Members: ${response.data?.member_count}`);
レスポンス
{
"data": {
"id": "1234567890",
"name": "Tech News",
"description": "Top tech journalists and publications",
"owner_id": "2244994945",
"private": false,
"member_count": 50,
"follower_count": 1250,
"created_at": "2023-01-15T10:00:00.000Z"
}
}
ユーザーが所有するリストを取得する
cURL
curl "https://api.x.com/2/users/2244994945/owned_lists?\
list.fields=description,member_count,follower_count&\
max_results=100" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# ページネーションを使用してユーザーが所有するリストを取得します
for page in client.lists.get_owned_lists(
"2244994945",
list_fields=["description", "member_count", "follower_count"],
max_results=100
):
for lst in page.data:
print(f"{lst.name} - {lst.member_count} members")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// ページネーションを使用してユーザーが所有するリストを取得します
const paginator = client.lists.getOwnedLists("2244994945", {
listFields: ["description", "member_count", "follower_count"],
maxResults: 100,
});
for await (const page of paginator) {
page.data?.forEach((lst) => {
console.log(`${lst.name} - ${lst.member_count} members`);
});
}
レスポンス
{
"data": [
{
"id": "1234567890",
"name": "Tech News",
"description": "Top tech journalists",
"member_count": 50,
"follower_count": 1250
},
{
"id": "9876543210",
"name": "Developer Tools",
"description": "Useful tools for developers",
"member_count": 25,
"follower_count": 500
}
],
"meta": {
"result_count": 2
}
}
所有者情報を含める
cURL
curl "https://api.x.com/2/lists/1234567890?\
list.fields=description,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")
# 所有者情報付きのリストを取得
response = client.lists.get(
"1234567890",
list_fields=["description", "owner_id"],
expansions=["owner_id"],
user_fields=["username", "verified"]
)
print(f"List: {response.data.name}")
# 所有者情報は response.includes.users に含まれます
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// 所有者情報付きのリストを取得
const response = await client.lists.get("1234567890", {
listFields: ["description", "owner_id"],
expansions: ["owner_id"],
userFields: ["username", "verified"],
});
console.log(`List: ${response.data?.name}`);
// 所有者情報は response.includes?.users に含まれます
拡張を含むレスポンス
{
"data": {
"id": "1234567890",
"name": "Tech News",
"description": "Top tech journalists",
"owner_id": "2244994945"
},
"includes": {
"users": [
{
"id": "2244994945",
"username": "XDevelopers",
"verified": true
}
]
}
}
使用可能なフィールド
| フィールド | 説明 |
|---|---|
description | リストの説明 |
owner_id | オーナーのユーザー ID |
private | リストが非公開かどうか |
member_count | メンバー数 |
follower_count | フォロワー数 |
created_at | リストの作成日時 |
次のステップ
リストの投稿
リストから投稿を取得
リストのメンバー
リストのメンバーを取得
リストを管理
リストを作成・更新
APIリファレンス
エンドポイントの詳細なドキュメント