사전 요구사항시작하기 전에 다음이 필요합니다:
- 승인된 App이 있는 developer account
- App의 Bearer Token(공개 데이터용) 또는 User Access Token(비공개 지표용)
게시물을 리트윗한 사용자 가져오기
1
Post ID 찾기
Retweets를 조회할 게시물의 ID를 확인합니다:
https://x.com/XDevelopers/status/1354143047324299264
└── This is the Post ID
2
요청 보내기
cURL
curl "https://api.x.com/2/tweets/1354143047324299264/retweeted_by?\
user.fields=created_at,username,verified" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get users who Retweeted a Post with pagination
for page in client.posts.get_retweeted_by(
"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" });
// Get users who Retweeted a Post with pagination
const paginator = client.posts.getRetweetedBy("1354143047324299264", {
userFields: ["created_at", "username", "verified"],
});
for await (const page of paginator) {
page.data?.forEach((user) => {
console.log(`${user.username} - Joined: ${user.created_at}`);
});
}
3
응답 확인
{
"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"
}
}
추가 데이터 포함
expansion을 사용해 고정 게시물과 같은 관련 데이터를 가져옵니다:cURL
curl "https://api.x.com/2/tweets/1354143047324299264/retweeted_by?\
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")
# Get Retweeting users with expansions
for page in client.posts.get_retweeted_by(
"1354143047324299264",
user_fields=["created_at"],
expansions=["pinned_tweet_id"],
tweet_fields=["created_at"]
):
for user in page.data:
print(f"{user.username}")
# Pinned Posts are in page.includes.tweets
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get Retweeting users with expansions
const paginator = client.posts.getRetweetedBy("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);
});
// Pinned Posts are in page.includes?.tweets
}
expansion을 포함한 응답
{
"data": [
{
"pinned_tweet_id": "1389270063807598594",
"created_at": "2018-11-21T14:24:58.000Z",
"id": "1065249714214457345",
"username": "TwitterSpaces",
"name": "Spaces"
}
],
"includes": {
"tweets": [
{
"created_at": "2021-05-03T17:26:09.000Z",
"id": "1389270063807598594",
"text": "now, everyone with 600 or more followers can host a Space..."
}
]
}
}
다음 단계
Retweets 관리
Retweet 및 취소
Quote Posts
Quote Posts 가져오기
API 레퍼런스
전체 엔드포인트 문서