Documentation Index
Fetch the complete documentation index at: https://generaltranslation.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
이 가이드는 실시간 계정 활동 이벤트를 받기 위해 activity 스트림 구독을 설정하는 방법을 설명합니다.
사전 준비 사항시작하기 전에 다음이 필요합니다.
- 승인된 App이 있는 개발자 계정
- App의 Bearer 토큰
구독 생성
특정 사용자의 활동 이벤트를 구독합니다.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 "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"
}
]
}
| 이벤트 | 설명 |
|---|
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 DELETE "https://api.x.com/2/activity/subscriptions/1234567890" \
-H "Authorization: Bearer $BEARER_TOKEN"
Account Activity API
웹훅 기반 대안