投稿にいいねを付けたユーザーを取得する
特定の投稿にいいねを付けたユーザーのリストを取得します:cURL
curl "https://api.x.com/2/tweets/1354143047324299264/liking_users?\
user.fields=created_at,username,verified" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# ページネーションで投稿にいいねを付けたユーザーを取得
for page in client.posts.get_liking_users(
"1354143047324299264",
user_fields=["created_at", "username", "verified"]
):
for user in page.data:
print(f"{user.username} - Joined: {user.created_at}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// ページネーションで投稿にいいねを付けたユーザーを取得
const paginator = client.posts.getLikingUsers("1354143047324299264", {
userFields: ["created_at", "username", "verified"],
});
for await (const page of paginator) {
page.data?.forEach((user) => {
console.log(`${user.username} - Joined: ${user.created_at}`);
});
}
レスポンス
{
"data": [
{
"created_at": "2008-12-04T18:51:57.000Z",
"id": "17874544",
"username": "TwitterSupport",
"name": "Twitter Support",
"verified": true
},
{
"created_at": "2007-02-20T14:35:54.000Z",
"id": "783214",
"username": "Twitter",
"name": "Twitter",
"verified": true
}
],
"meta": {
"result_count": 2,
"next_token": "7140dibdnow9c7btw3z2vwioavpvutgzrzm9icis4ndix"
}
}
ユーザーがいいねを付けた投稿を取得する
特定のユーザーがいいねを付けた投稿を取得します:cURL
curl "https://api.x.com/2/users/2244994945/liked_tweets?\
tweet.fields=created_at,public_metrics&\
max_results=10" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# ページネーションでユーザーがいいねを付けた投稿を取得
for page in client.users.get_liked_tweets(
"2244994945",
tweet_fields=["created_at", "public_metrics"],
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({ bearerToken: "YOUR_BEARER_TOKEN" });
// ページネーションでユーザーがいいねを付けた投稿を取得
const paginator = client.users.getLikedTweets("2244994945", {
tweetFields: ["created_at", "public_metrics"],
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}`);
});
}
レスポンス
{
"data": [
{
"id": "1362449997430542337",
"text": "Honored to be the first developer to be featured...",
"created_at": "2021-02-18T17:45:00.000Z",
"public_metrics": {
"retweet_count": 5,
"reply_count": 2,
"like_count": 42,
"quote_count": 1
}
}
],
"meta": {
"result_count": 1,
"next_token": "7140dibdnow9c7btw4539n0vybdnx19ylpayqf16fjt4l"
}
}
追加データを含める
expansions を使用して固定投稿などの関連データを取得します:cURL
curl "https://api.x.com/2/tweets/1354143047324299264/liking_users?\
user.fields=created_at&\
expansions=pinned_tweet_id&\
tweet.fields=created_at" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# 固定投稿の expansion 付きで、いいねを付けたユーザーを取得
for page in client.posts.get_liking_users(
"1354143047324299264",
user_fields=["created_at"],
expansions=["pinned_tweet_id"],
tweet_fields=["created_at"]
):
for user in page.data:
print(f"{user.username}")
# 固定投稿は page.includes.tweets にあります
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// 固定投稿の expansion 付きで、いいねを付けたユーザーを取得
const paginator = client.posts.getLikingUsers("1354143047324299264", {
userFields: ["created_at"],
expansions: ["pinned_tweet_id"],
tweetFields: ["created_at"],
});
for await (const page of paginator) {
page.data?.forEach((user) => {
console.log(user.username);
});
// 固定投稿は page.includes?.tweets にあります
}
次のステップ
いいねを管理
投稿にいいねを付ける・外す
API リファレンス
エンドポイントの完全なドキュメント