구독 생성
특정 사용자의 활동 이벤트를 구독합니다.응답:
- cURL
- Python
curl -X POST "https://api.x.com/2/activity/subscriptions" \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"user_id": "2244994945",
"event_types": ["tweet_create_events", "favorite_events", "follow_events"]
}'
import requests
bearer_token = "YOUR_BEARER_TOKEN"
url = "https://api.x.com/2/activity/subscriptions"
headers = {
"Authorization": f"Bearer {bearer_token}",
"Content-Type": "application/json"
}
payload = {
"user_id": "2244994945",
"event_types": ["tweet_create_events", "favorite_events", "follow_events"]
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
{
"data": {
"id": "1234567890",
"user_id": "2244994945",
"event_types": ["tweet_create_events", "favorite_events", "follow_events"],
"created_at": "2024-01-15T10:00:00.000Z"
}
}
스트림에 연결
이벤트를 수신할 수 있도록 지속 연결을 엽니다.
- cURL
- Python
curl "https://api.x.com/2/activity/stream" \
-H "Authorization: Bearer $BEARER_TOKEN"
import requests
bearer_token = "YOUR_BEARER_TOKEN"
url = "https://api.x.com/2/activity/stream"
headers = {"Authorization": f"Bearer {bearer_token}"}
response = requests.get(url, headers=headers, stream=True)
for line in response.iter_lines():
if line:
print(line.decode("utf-8"))
수신 이벤트 처리
이벤트는 JSON 객체 형태로 스트리밍됩니다.
{
"for_user_id": "2244994945",
"event_type": "tweet_create_events",
"created_at": "2024-01-15T10:30:00.000Z",
"tweet_create_events": [
{
"id": "1234567890",
"text": "Hello from the stream!",
"author_id": "2244994945"
}
]
}
사용 가능한 이벤트 type
| 이벤트 | 설명 |
|---|---|
tweet_create_events | 사용자가 새 게시물을 게시함 |
favorite_events | 사용자가 게시물에 좋아요를 표시함 |
follow_events | 사용자가 다른 사용자를 팔로우하거나 팔로우됨 |
direct_message_events | 사용자가 DM을 보내거나 받음 |
block_events | 사용자가 차단하거나 차단 해제함 |
mute_events | 사용자가 뮤트하거나 뮤트 해제함 |
구독 관리
구독 목록 조회
구독 목록 조회
활성 구독을 모두 조회합니다:
curl "https://api.x.com/2/activity/subscriptions" \
-H "Authorization: Bearer $BEARER_TOKEN"
구독 업데이트
구독 업데이트
구독의 이벤트 유형을 수정합니다:
curl -X PUT "https://api.x.com/2/activity/subscriptions/1234567890" \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"event_types": ["tweet_create_events", "favorite_events"]
}'
구독 삭제
구독 삭제
구독을 삭제합니다:
curl -X DELETE "https://api.x.com/2/activity/subscriptions/1234567890" \
-H "Authorization: Bearer $BEARER_TOKEN"
다음 단계
Account Activity API
웹훅 기반 대안
API 참조 문서
전체 엔드포인트 문서