메인 콘텐츠로 건너뛰기
이 가이드는 실시간 계정 활동 이벤트를 받기 위해 activity 스트림 구독을 설정하는 방법을 설명합니다.
사전 준비 사항시작하기 전에 다음이 필요합니다.

구독 생성

특정 사용자의 활동 이벤트를 구독합니다.
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"]
  }'
응답:
{
  "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"

수신 이벤트 처리

이벤트는 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 참조 문서

전체 엔드포인트 문서