> ## 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 Stream エンドポイントは、サブスクライブしているユーザーのアカウントアクティビティイベントをリアルタイムで配信します。ユーザーがポスト、いいね、フォロー、DM の受信などを行った際のイベントを受信できます。

<div id="overview">
  ## 概要
</div>

<CardGroup cols={2}>
  <Card title="リアルタイム" icon="bolt">
    イベントを即時配信
  </Card>

  <Card title="包括的" icon="list">
    投稿、いいね、フォロー、DM など
  </Card>

  <Card title="サブスクリプション型" icon="bell">
    ユーザーアクティビティを購読
  </Card>

  <Card title="Webhook 配信" icon="webhook">
    イベントをあなたのサーバーに配信
  </Card>
</CardGroup>

***

<div id="event-types">
  ## イベントタイプ
</div>

| イベント                    | 説明                     |
| :---------------------- | :--------------------- |
| `tweet_create_events`   | ユーザーが新しいポストを作成する       |
| `favorite_events`       | ユーザーがポストにいいねする         |
| `follow_events`         | ユーザーがフォローする、またはフォローされる |
| `direct_message_events` | ユーザーがDMを送信または受信する      |
| `block_events`          | ユーザーがブロックまたはブロック解除する   |
| `mute_events`           | ユーザーがミュートまたはミュート解除する   |

***

<div id="endpoints">
  ## エンドポイント
</div>

| メソッド   | エンドポイント                                                                               | 説明              |
| :----- | :------------------------------------------------------------------------------------ | :-------------- |
| GET    | [`/2/activity/stream`](/ja/x-api/activity/activity-stream)                            | アクティビティストリームに接続 |
| POST   | [`/2/activity/subscriptions`](/ja/x-api/activity/create-x-activity-subscription)      | サブスクリプションを作成    |
| GET    | [`/2/activity/subscriptions`](/ja/x-api/activity/get-x-activity-subscriptions)        | サブスクリプションの一覧を取得 |
| PUT    | [`/2/activity/subscriptions/:id`](/ja/x-api/activity/update-x-activity-subscription)  | サブスクリプションを更新    |
| DELETE | [`/2/activity/subscriptions/:id`](/ja/x-api/activity/deletes-x-activity-subscription) | サブスクリプションを削除    |

***

<div id="how-it-works">
  ## 仕組み
</div>

1. **サブスクリプションを作成** — ユーザーアクティビティの購読を開始する
2. **ストリームに接続** — 持続的な接続を確立する
3. **イベントを受信** — リアルタイムのアクティビティイベントを取得する
4. **イベントを処理** — アプリケーション側でイベントを処理する

***

<div id="example-connect-to-stream">
  ## 例：ストリームに接続する
</div>

```python theme={null}
import requests

def stream_activity(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"))
```

***

<div id="getting-started">
  ## はじめに
</div>

<Note>
  **前提条件**

  * 承認済みの[開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * 開発者コンソール内の[Project と App](/ja/resources/fundamentals/developer-apps)
  * App の[ベアラートークン](/ja/resources/fundamentals/authentication)
</Note>

<CardGroup cols={2}>
  <Card title="クイックスタート" icon="rocket" href="/ja/x-api/activity/quickstart">
    最初のサブスクリプションを設定する
  </Card>

  <Card title="Account Activity API" icon="bell" href="/ja/x-api/account-activity/introduction">
    Webhook ベースの代替手段
  </Card>

  <Card title="APIリファレンス" icon="code" href="/ja/x-api/activity/activity-stream">
    エンドポイントの詳細ドキュメント
  </Card>
</CardGroup>
