사전 요구사항시작하기 전에 다음이 필요합니다:
- 승인된 App이 있는 developer account
- App의 Bearer Token(Developer Console의 “Keys and tokens”에서 확인)
1
Post ID 찾기
모든 게시물에는 고유한 ID가 있습니다. 게시물 URL에서 확인할 수 있습니다:
https://x.com/XDevelopers/status/1228393702244134912
└── This is the Post ID
2
요청 만들기
cURL
curl "https://api.x.com/2/tweets/1228393702244134912" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get a single Post by ID
response = client.posts.get("1228393702244134912")
print(response.data)
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
const response = await client.posts.get("1228393702244134912");
console.log(response.data);
3
응답 확인
기본 응답에는 게시물의
id, text, edit_history_tweet_ids가 포함됩니다:{
"data": {
"id": "1228393702244134912",
"text": "What did the developer write in their Valentine's card?\n\nwhile(true) {\n I = Love(You);\n}",
"edit_history_tweet_ids": ["1228393702244134912"]
}
}
4
추가 필드 요청
쿼리 파라미터를 사용해 더 많은 데이터를 가져옵니다:응답:
예시 응답
cURL
curl "https://api.x.com/2/tweets/1228393702244134912?\
tweet.fields=created_at,public_metrics,author_id&\
expansions=author_id&\
user.fields=username,verified" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get a Post with additional fields and expansions
response = client.posts.get(
"1228393702244134912",
tweet_fields=["created_at", "public_metrics", "author_id"],
expansions=["author_id"],
user_fields=["username", "verified"]
)
print(response.data)
print(response.includes) # Contains author user object
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
const response = await client.posts.get("1228393702244134912", {
tweetFields: ["created_at", "public_metrics", "author_id"],
expansions: ["author_id"],
userFields: ["username", "verified"],
});
console.log(response.data);
console.log(response.includes); // Contains author user object
{
"data": {
"id": "1228393702244134912",
"text": "What did the developer write in their Valentine's card?...",
"created_at": "2020-02-14T19:00:55.000Z",
"author_id": "2244994945",
"public_metrics": {
"retweet_count": 156,
"reply_count": 23,
"like_count": 892,
"quote_count": 12
},
"edit_history_tweet_ids": ["1228393702244134912"]
},
"includes": {
"users": [
{
"id": "2244994945",
"username": "XDevelopers",
"verified": true
}
]
}
}
5
다중 게시물 조회
한 번의 요청으로 최대 100개의 게시물을 조회합니다:
cURL
curl "https://api.x.com/2/tweets?\
ids=1228393702244134912,1227640996038684673,1199786642791452673&\
tweet.fields=created_at,author_id" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get multiple Posts by IDs
response = client.posts.get_posts(
ids=["1228393702244134912", "1227640996038684673", "1199786642791452673"],
tweet_fields=["created_at", "author_id"]
)
for post in response.data:
print(f"{post.id}: {post.text[:50]}...")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
const response = await client.posts.getPosts({
ids: ["1228393702244134912", "1227640996038684673", "1199786642791452673"],
tweetFields: ["created_at", "author_id"],
});
response.data?.forEach((post) => {
console.log(`${post.id}: ${post.text?.slice(0, 50)}...`);
});
다음 단계
통합 가이드
인증, rate limit, 모범 사례 익히기
Fields 및 expansions
fields와 expansions 시스템 마스터하기
API 레퍼런스
사용 가능한 모든 파라미터 보기
샘플 코드
더 많은 예제 살펴보기