사전 요구사항시작하기 전에 다음이 필요합니다:
- 승인된 App이 포함된 developer account
- App의 Bearer Token (조회용)
- User Access Token (팔로우 관리용)
사용자의 팔로워 가져오기
특정 사용자를 팔로우하는 사용자 목록을 조회합니다:cURL
curl "https://api.x.com/2/users/2244994945/followers?\
user.fields=username,verified,public_metrics&\
max_results=100" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# 페이지네이션으로 사용자의 팔로워 가져오기
for page in client.users.get_followers(
"2244994945",
user_fields=["username", "verified", "public_metrics"],
max_results=100
):
for user in page.data:
print(f"{user.username} - Followers: {user.public_metrics.followers_count}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// 페이지네이션으로 사용자의 팔로워 가져오기
const paginator = client.users.getFollowers("2244994945", {
userFields: ["username", "verified", "public_metrics"],
maxResults: 100,
});
for await (const page of paginator) {
page.data?.forEach((user) => {
console.log(`${user.username} - Followers: ${user.public_metrics?.followers_count}`);
});
}
응답
{
"data": [
{
"id": "1234567890",
"name": "Developer",
"username": "dev_user",
"verified": false,
"public_metrics": {
"followers_count": 500,
"following_count": 200,
"tweet_count": 1500
}
}
],
"meta": {
"result_count": 1,
"next_token": "abc123"
}
}
사용자가 팔로우하는 계정 가져오기
특정 사용자가 팔로우하는 사용자 목록을 조회합니다:cURL
curl "https://api.x.com/2/users/2244994945/following?\
user.fields=username,verified&\
max_results=100" \
-H "Authorization: Bearer $BEARER_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_BEARER_TOKEN")
# 사용자가 팔로우하는 계정 가져오기
for page in client.users.get_following(
"2244994945",
user_fields=["username", "verified"],
max_results=100
):
for user in page.data:
print(f"{user.username} - Verified: {user.verified}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });
// 사용자가 팔로우하는 계정 가져오기
const paginator = client.users.getFollowing("2244994945", {
userFields: ["username", "verified"],
maxResults: 100,
});
for await (const page of paginator) {
page.data?.forEach((user) => {
console.log(`${user.username} - Verified: ${user.verified}`);
});
}
사용자 팔로우
인증된 사용자를 대신하여 사용자를 팔로우합니다:cURL
curl -X POST "https://api.x.com/2/users/123456789/following" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"target_user_id": "2244994945"}'
from xdk import Client
from xdk.oauth1_auth import OAuth1
oauth1 = OAuth1(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
access_token="YOUR_ACCESS_TOKEN",
access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
)
client = Client(auth=oauth1)
# 사용자 팔로우
response = client.users.follow(
source_user_id="123456789",
target_user_id="2244994945"
)
print(f"Following: {response.data.following}")
import { Client, OAuth1 } from "@xdevplatform/xdk";
const oauth1 = new OAuth1({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
accessToken: "YOUR_ACCESS_TOKEN",
accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
});
const client = new Client({ oauth1 });
// 사용자 팔로우
const response = await client.users.follow("123456789", {
targetUserId: "2244994945",
});
console.log(`Following: ${response.data?.following}`);
응답
{
"data": {
"following": true,
"pending_follow": false
}
}
대상 계정이 비공개인 경우 팔로우 요청이 승인될 때까지
pending_follow가 true가 됩니다.사용자 언팔로우
인증된 사용자를 대신하여 사용자를 언팔로우합니다:cURL
curl -X DELETE "https://api.x.com/2/users/123456789/following/2244994945" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
from xdk import Client
from xdk.oauth1_auth import OAuth1
oauth1 = OAuth1(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
access_token="YOUR_ACCESS_TOKEN",
access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
)
client = Client(auth=oauth1)
# 사용자 언팔로우
response = client.users.unfollow(
source_user_id="123456789",
target_user_id="2244994945"
)
print(f"Following: {response.data.following}")
import { Client, OAuth1 } from "@xdevplatform/xdk";
const oauth1 = new OAuth1({
apiKey: "YOUR_API_KEY",
apiSecret: "YOUR_API_SECRET",
accessToken: "YOUR_ACCESS_TOKEN",
accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
});
const client = new Client({ oauth1 });
// 사용자 언팔로우
const response = await client.users.unfollow("123456789", "2244994945");
console.log(`Following: ${response.data?.following}`);
응답
{
"data": {
"following": false
}
}
공통 매개변수
| Parameter | Description |
|---|---|
max_results | 페이지당 결과 수 (1-1000, 기본값 100) |
pagination_token | 다음 페이지용 토큰 |
user.fields | 추가 user 필드 |
expansions | 포함할 관련 객체 |
다음 단계
User lookup
사용자 프로필 조회
Blocks
사용자 차단 및 차단 해제
Mutes
사용자 뮤트 및 뮤트 해제
API 레퍼런스
전체 엔드포인트 문서