前提条件始める前に、以下が必要です:
- 承認済みの App がある developer account
- ユーザー Access Token (OAuth 1.0a または OAuth 2.0 PKCE)
List を作成
1
リクエストを準備
List の name (必須)、およびオプションで description と非公開設定を定義します:
{
"name": "Tech News",
"description": "Top tech journalists and publications",
"private": false
}
2
リクエストを送信
cURL
curl -X POST "https://api.x.com/2/lists" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tech News",
"description": "Top tech journalists and publications",
"private": false
}'
from xdk import Client
from xdk.oauth1_auth import OAuth1
oauth1 = OAuth1(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
access_token="YOUR_ACCESS_TOKEN",
access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
)
client = Client(auth=oauth1)
# 新しい List を作成
response = client.lists.create(
name="Tech News",
description="Top tech journalists and publications",
private=False
)
print(f"List created: {response.data.id} - {response.data.name}")
import { Client, OAuth1 } from "@xdevplatform/xdk";
const oauth1 = new OAuth1({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
accessToken: "YOUR_ACCESS_TOKEN",
accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
});
const client = new Client({ oauth1 });
// 新しい List を作成
const response = await client.lists.create({
name: "Tech News",
description: "Top tech journalists and publications",
private: false,
});
console.log(`List created: ${response.data?.id} - ${response.data?.name}`);
3
レスポンスを確認
{
"data": {
"id": "1441162269824405510",
"name": "Tech News"
}
}
id を保存しておきます。List を更新
List の名前、説明、または非公開設定を変更します:cURL
curl -X PUT "https://api.x.com/2/lists/1441162269824405510" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tech News & Insights",
"description": "Updated description"
}'
from xdk import Client
from xdk.oauth1_auth import OAuth1
oauth1 = OAuth1(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
access_token="YOUR_ACCESS_TOKEN",
access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
)
client = Client(auth=oauth1)
# List を更新
response = client.lists.update(
"1441162269824405510",
name="Tech News & Insights",
description="Updated description"
)
print(f"Updated: {response.data.updated}")
import { Client, OAuth1 } from "@xdevplatform/xdk";
const oauth1 = new OAuth1({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
accessToken: "YOUR_ACCESS_TOKEN",
accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
});
const client = new Client({ oauth1 });
// List を更新
const response = await client.lists.update("1441162269824405510", {
name: "Tech News & Insights",
description: "Updated description",
});
console.log(`Updated: ${response.data?.updated}`);
{
"data": {
"updated": true
}
}
List を削除
1
List ID を取得
削除したい List の ID が必要です。
2
削除リクエストを送信
cURL
curl -X DELETE "https://api.x.com/2/lists/1441162269824405510" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
from xdk import Client
from xdk.oauth1_auth import OAuth1
oauth1 = OAuth1(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
access_token="YOUR_ACCESS_TOKEN",
access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
)
client = Client(auth=oauth1)
# List を削除
response = client.lists.delete("1441162269824405510")
print(f"Deleted: {response.data.deleted}")
import { Client, OAuth1 } from "@xdevplatform/xdk";
const oauth1 = new OAuth1({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
accessToken: "YOUR_ACCESS_TOKEN",
accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
});
const client = new Client({ oauth1 });
// List を削除
const response = await client.lists.delete("1441162269824405510");
console.log(`Deleted: ${response.data?.deleted}`);
3
削除を確認
{
"data": {
"deleted": true
}
}
削除できるのは自分が所有する List のみです。
次のステップ
List members
List のメンバーの追加・削除
List lookup
List の詳細を取得
連携ガイド
主要な概念とベストプラクティス
API リファレンス
エンドポイントの詳細ドキュメント