ブックマークを取得する
1
ユーザー ID を取得する
認証済みユーザーの ID が必要です。
/2/users/me エンドポイントまたはユーザールックアップエンドポイントで確認できます。2
ブックマークをリクエストする
cURL
curl "https://api.x.com/2/users/2244994945/bookmarks?\
tweet.fields=created_at,public_metrics,author_id&\
max_results=10" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")
# ページネーションでブックマークした投稿を取得
for page in client.bookmarks.get(
"2244994945",
tweet_fields=["created_at", "public_metrics", "author_id"],
max_results=10
):
for post in page.data:
print(f"{post.text[:50]}... - Likes: {post.public_metrics.like_count}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });
// ページネーションでブックマークした投稿を取得
const paginator = client.bookmarks.get("2244994945", {
tweetFields: ["created_at", "public_metrics", "author_id"],
maxResults: 10,
});
for await (const page of paginator) {
page.data?.forEach((post) => {
console.log(`${post.text?.slice(0, 50)}... - Likes: ${post.public_metrics?.like_count}`);
});
}
3
レスポンスを確認する
{
"data": [
{
"id": "1501258597237342208",
"text": "Have you built a project using the X API you'd like to share with the community? We'd love to hear from you!",
"created_at": "2024-01-15T10:30:00.000Z",
"author_id": "2244994945",
"public_metrics": {
"retweet_count": 15,
"reply_count": 8,
"like_count": 89,
"quote_count": 3
}
},
{
"id": "1501258542258348032",
"text": "This is just one way developer innovation helps make X a better place...",
"created_at": "2024-01-15T09:15:00.000Z",
"author_id": "2244994945",
"public_metrics": {
"retweet_count": 22,
"reply_count": 5,
"like_count": 156,
"quote_count": 7
}
}
],
"meta": {
"result_count": 2,
"next_token": "7140dibdnow9c7btw4539n0vybdnx19ylpayqf16fjt4l"
}
}
投稿者情報を含める
expansions を使用して投稿の作者データを取得します:cURL
curl "https://api.x.com/2/users/2244994945/bookmarks?\
tweet.fields=created_at,author_id&\
expansions=author_id&\
user.fields=username,verified" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")
# 作者情報付きでブックマークを取得
for page in client.bookmarks.get(
"2244994945",
tweet_fields=["created_at", "author_id"],
expansions=["author_id"],
user_fields=["username", "verified"]
):
for post in page.data:
print(f"{post.text[:50]}...")
# 作者情報は page.includes.users にあります
import { Client } from "@xdevplatform/xdk";
const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });
// 作者情報付きでブックマークを取得
const paginator = client.bookmarks.get("2244994945", {
tweetFields: ["created_at", "author_id"],
expansions: ["author_id"],
userFields: ["username", "verified"],
});
for await (const page of paginator) {
page.data?.forEach((post) => {
console.log(`${post.text?.slice(0, 50)}...`);
});
// 作者情報は page.includes?.users にあります
}
必要なスコープ
OAuth 2.0 PKCE を使用する場合、アクセストークンには以下のスコープが必要です:| Scope | Description |
|---|---|
bookmark.read | ブックマークを読み取り |
tweet.read | 投稿データを読み取り |
users.read | ユーザーデータを読み取り(expansions 用) |
次のステップ
ブックマークを管理
ブックマークの追加と削除
API リファレンス
エンドポイントの完全なドキュメント