차단한 사용자 가져오기
1
내 사용자 ID 가져오기
차단 목록을 가져오려면 인증된 사용자의 ID가 필요합니다.
/2/users/me 엔드포인트에서 가져오거나 토큰에 포함된 ID를 사용할 수 있습니다.2
차단 목록 요청하기
cURL
curl "https://api.x.com/2/users/123456789/blocking?\
user.fields=username,verified,created_at&\
max_results=100" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN"
from xdk import Client
client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")
# 페이지네이션을 사용하여 차단한 사용자 가져오기
for page in client.users.get_blocking(
"123456789",
user_fields=["username", "verified", "created_at"],
max_results=100
):
for user in page.data:
print(f"{user.username} - Created: {user.created_at}")
import { Client } from "@xdevplatform/xdk";
const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });
// 페이지네이션을 사용하여 차단한 사용자 가져오기
const paginator = client.users.getBlocking("123456789", {
userFields: ["username", "verified", "created_at"],
maxResults: 100,
});
for await (const page of paginator) {
page.data?.forEach((user) => {
console.log(`${user.username} - Created: ${user.created_at}`);
});
}
3
응답 확인하기
{
"data": [
{
"id": "17874544",
"name": "Example User",
"username": "example_user",
"verified": false,
"created_at": "2008-12-04T18:51:57.000Z"
}
],
"meta": {
"result_count": 1,
"next_token": "abc123"
}
}
사용자 차단
1
대상 사용자 식별
차단하려는 계정의 사용자 ID를 확인합니다.
2
차단 요청 보내기
cURL
curl -X POST "https://api.x.com/2/users/123456789/blocking" \
-H "Authorization: Bearer $USER_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"target_user_id": "9876543210"}'
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.block(
source_user_id="123456789",
target_user_id="9876543210"
)
print(f"Blocking: {response.data.blocking}")
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.block("123456789", {
targetUserId: "9876543210",
});
console.log(`Blocking: ${response.data?.blocking}`);
3
차단 확인
{
"data": {
"blocking": true
}
}
사용자 차단 해제
1
차단 해제 요청 보내기
cURL
curl -X DELETE "https://api.x.com/2/users/123456789/blocking/9876543210" \
-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.unblock(
source_user_id="123456789",
target_user_id="9876543210"
)
print(f"Blocking: {response.data.blocking}")
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.unblock("123456789", "9876543210");
console.log(`Blocking: ${response.data?.blocking}`);
2
차단 해제 확인하기
{
"data": {
"blocking": false
}
}
다음 단계
뮤트
차단 대신 사용자를 뮤트하세요
팔로우
팔로우를 관리하세요
통합 가이드
핵심 개념과 모범 사례
API 참조 문서
전체 엔드포인트 문서