> ## Documentation Index
> Fetch the complete documentation index at: https://generaltranslation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 빠른 시작

> 활동 스트림 구독을 설정하고 이벤트를 받아보세요

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

이 가이드는 실시간 계정 활동 이벤트를 받기 위해 activity 스트림 구독을 설정하는 방법을 설명합니다.

<Note>
  **사전 준비 사항**

  시작하기 전에 다음이 필요합니다.

  * 승인된 App이 있는 [개발자 계정](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App의 Bearer 토큰
</Note>

***

<Steps>
  <Step title="구독 생성" icon="bell">
    특정 사용자의 활동 이벤트를 구독합니다.

    <Tabs>
      <Tab title="cURL">
        ```bash theme={null}
        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"]
          }'
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        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())
        ```
      </Tab>
    </Tabs>

    **응답:**

    ```json theme={null}
    {
      "data": {
        "id": "1234567890",
        "user_id": "2244994945",
        "event_types": ["tweet_create_events", "favorite_events", "follow_events"],
        "created_at": "2024-01-15T10:00:00.000Z"
      }
    }
    ```
  </Step>

  <Step title="스트림에 연결" icon="plug">
    이벤트를 수신할 수 있도록 지속 연결을 엽니다.

    <Tabs>
      <Tab title="cURL">
        ```bash theme={null}
        curl "https://api.x.com/2/activity/stream" \
          -H "Authorization: Bearer $BEARER_TOKEN"
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        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"))
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="수신 이벤트 처리" icon="message">
    이벤트는 JSON 객체 형태로 스트리밍됩니다.

    ```json theme={null}
    {
      "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"
        }
      ]
    }
    ```
  </Step>
</Steps>

***

<div id="available-event-types">
  ## 사용 가능한 이벤트 type
</div>

| 이벤트                     | 설명                       |
| :---------------------- | :----------------------- |
| `tweet_create_events`   | 사용자가 새 게시물을 게시함          |
| `favorite_events`       | 사용자가 게시물에 좋아요를 표시함       |
| `follow_events`         | 사용자가 다른 사용자를 팔로우하거나 팔로우됨 |
| `direct_message_events` | 사용자가 DM을 보내거나 받음         |
| `block_events`          | 사용자가 차단하거나 차단 해제함        |
| `mute_events`           | 사용자가 뮤트하거나 뮤트 해제함        |

***

<div id="manage-subscriptions">
  ## 구독 관리
</div>

<AccordionGroup>
  <Accordion title="구독 목록 조회">
    활성 구독을 모두 조회합니다:

    ```bash theme={null}
    curl "https://api.x.com/2/activity/subscriptions" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Accordion>

  <Accordion title="구독 업데이트">
    구독의 이벤트 유형을 수정합니다:

    ```bash theme={null}
    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"]
      }'
    ```
  </Accordion>

  <Accordion title="구독 삭제">
    구독을 삭제합니다:

    ```bash theme={null}
    curl -X DELETE "https://api.x.com/2/activity/subscriptions/1234567890" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Accordion>
</AccordionGroup>

***

<div id="next-steps">
  ## 다음 단계
</div>

<CardGroup cols={2}>
  <Card title="Account Activity API" icon="bell" href="/ko/x-api/account-activity/introduction">
    웹훅 기반 대안
  </Card>

  <Card title="API 참조 문서" icon="code" href="/ko/x-api/activity/activity-stream">
    전체 엔드포인트 문서
  </Card>
</CardGroup>
