사전 요구사항시작하기 전에 다음이 필요합니다:
- 승인된 App이 있는 developer account
- App의 Bearer Token(공개 데이터용) 또는 User Access Token(비공개 지표용)
User mentions 가져오기
1
user ID 확인
user lookup 엔드포인트를 사용해 user ID를 확인합니다. 예를 들어 @XDevelopers의 user ID는
2244994945입니다.2
mentions 타임라인 요청
cURL
curl "https://api.x.com/2/users/2244994945/mentions?\
tweet.fields=created_at,public_metrics,author_id&\
expansions=author_id&\
user.fields=username,verified&\
max_results=10" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get mentions timeline with pagination
for page in client.posts.get_user_mentions(
"2244994945",
tweet_fields=["created_at", "public_metrics", "author_id"],
expansions=["author_id"],
user_fields=["username", "verified"],
max_results=10
):
for post in page.data:
print(f"@{post.author_id}: {post.text[:50]}...")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get mentions timeline with pagination
const paginator = client.posts.getUserMentions("2244994945", {
tweetFields: ["created_at", "public_metrics", "author_id"],
expansions: ["author_id"],
userFields: ["username", "verified"],
maxResults: 10,
});
for await (const page of paginator) {
page.data?.forEach((post) => {
console.log(`@${post.author_id}: ${post.text?.slice(0, 50)}...`);
});
}
3
응답 확인
{
"data": [
{
"id": "1301573587187331074",
"text": "Hey @XDevelopers, love the new API!",
"author_id": "1234567890",
"created_at": "2024-01-15T10:30:00.000Z",
"public_metrics": {
"retweet_count": 5,
"reply_count": 2,
"like_count": 42,
"quote_count": 1
}
}
],
"includes": {
"users": [
{
"id": "1234567890",
"username": "developer",
"name": "Dev Person",
"verified": false
}
]
},
"meta": {
"newest_id": "1301573587187331074",
"oldest_id": "1301573587187331074",
"result_count": 1,
"next_token": "t3buvdr5pujq9g7bggsnf3ep2ha28"
}
}
멘션 필터링
답글 제외
사용자를 멘션한 원본 게시물만 가져오기:cURL
curl "https://api.x.com/2/users/2244994945/mentions?\
exclude=replies&\
max_results=10" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get mentions excluding replies
for page in client.posts.get_user_mentions(
"2244994945",
exclude=["replies"],
max_results=10
):
for post in page.data:
print(post.text)
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get mentions excluding replies
const paginator = client.posts.getUserMentions("2244994945", {
exclude: ["replies"],
maxResults: 10,
});
for await (const page of paginator) {
page.data?.forEach((post) => {
console.log(post.text);
});
}
시간 범위 내 멘션 가져오기
cURL
curl "https://api.x.com/2/users/2244994945/mentions?\
start_time=2024-01-01T00%3A00%3A00Z&\
end_time=2024-01-31T23%3A59%3A59Z" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# Get mentions in a time range
for page in client.posts.get_user_mentions(
"2244994945",
start_time="2024-01-01T00:00:00Z",
end_time="2024-01-31T23:59:59Z"
):
for post in page.data:
print(f"{post.created_at}: {post.text[:50]}...")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// Get mentions in a time range
const paginator = client.posts.getUserMentions("2244994945", {
startTime: "2024-01-01T00:00:00Z",
endTime: "2024-01-31T23:59:59Z",
});
for await (const page of paginator) {
page.data?.forEach((post) => {
console.log(`${post.created_at}: ${post.text?.slice(0, 50)}...`);
});
}
공통 파라미터
| Parameter | Description | Default |
|---|---|---|
max_results | 페이지당 결과 수 (1-100) | 10 |
start_time | 가장 오래된 게시물 타임스탬프 (ISO 8601) | — |
end_time | 가장 최근 게시물 타임스탬프 (ISO 8601) | — |
since_id | 이 ID 이후의 게시물 반환 | — |
until_id | 이 ID 이전의 게시물 반환 | — |
exclude | retweets, replies 또는 둘 다 제외 | — |
pagination_token | 다음 페이지 토큰 | — |
다음 단계
Home timeline
사용자의 홈 타임라인 가져오기
통합 가이드
핵심 개념 및 모범 사례
API 레퍼런스
전체 엔드포인트 문서
페이지네이션 가이드
큰 결과 집합 탐색