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

# 連携ガイド

> このガイドでは、mutes エンドポイントをアプリケーションに連携するために必要な主要概念を説明します。X API v2 スタンダード階層の mutes に関するリファレンスドキュメントです。

export const Button = ({href, children}) => {
  return <div className="not-prose">
    <a href={href}>
      <button className="x-btn">
        <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>;
};

このガイドでは、mutes エンドポイントをアプリケーションに連携するために必要な主要概念を説明します。

***

## 認証

Mutes エンドポイントは、プライベートなミュートリストにアクセスするためにユーザー認証を必要とします:

| Method                                                                                                                         | Description    |
| :----------------------------------------------------------------------------------------------------------------------------- | :------------- |
| [OAuth 2.0 Authorization Code with PKCE](/resources/fundamentals/authentication#oauth-2-0-authorization-code-flow-with-pkce-2) | 新規アプリケーションには推奨 |
| [OAuth 1.0a User Context](/resources/fundamentals/authentication)                                                              | レガシーサポート       |

<Warning>
  App-Only 認証はサポートされていません。必ずユーザーの代理として認証する必要があります。
</Warning>

### 必要なスコープ (OAuth 2.0)

| Scope        | Required for      |
| :----------- | :---------------- |
| `mute.read`  | ミュート中のアカウントの取得    |
| `mute.write` | アカウントのミュート・ミュート解除 |
| `users.read` | mute 系スコープと併せて必要  |

***

## エンドポイントの概要

| Method | Endpoint                                          | Description       |
| :----- | :------------------------------------------------ | :---------------- |
| GET    | `/2/users/:id/muting`                             | ミュート中のアカウントの一覧を取得 |
| POST   | `/2/users/:id/muting`                             | アカウントをミュート        |
| DELETE | `/2/users/:source_user_id/muting/:target_user_id` | アカウントのミュートを解除     |

***

## Fields と expansions

### デフォルトのレスポンス

```json theme={null}
{
  "data": [
    {
      "id": "1234567890",
      "name": "Example User",
      "username": "example"
    }
  ]
}
```

### 利用可能なフィールド

<Accordion title="user.fields">
  | Field               | Description    |
  | :------------------ | :------------- |
  | `created_at`        | アカウント作成日       |
  | `description`       | ユーザーの bio      |
  | `profile_image_url` | アバターの URL      |
  | `public_metrics`    | フォロワー/フォロー中の件数 |
  | `verified`          | 認証済みステータス      |
</Accordion>

<Accordion title="expansions">
  | Expansion         | Description      |
  | :---------------- | :--------------- |
  | `pinned_tweet_id` | ユーザーのピン留めした Post |
</Accordion>

### フィールドを使った例

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/123456789/muting?\
  user.fields=username,verified,created_at&\
  max_results=100" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"
  ```

  ```python title="Python SDK" lines wrap icon="python" theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # 追加フィールド付きでミュート中のユーザーを取得
  for page in client.users.get_muting(
      user_id="123456789",
      user_fields=["username", "verified", "created_at"],
      max_results=100
  ):
      for user in page.data:
          print(f"{user.username} - Verified: {user.verified}")
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

  const paginator = client.users.getMuting("123456789", {
    userFields: ["username", "verified", "created_at"],
    maxResults: 100,
  });

  for await (const page of paginator) {
    page.data?.forEach((user) => {
      console.log(`${user.username} - Verified: ${user.verified}`);
    });
  }
  ```
</CodeGroup>

***

## ページネーション

ミュートリストが多いユーザーの場合、結果はページネーションされます:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  # 最初のリクエスト
  curl "https://api.x.com/2/users/123/muting?max_results=100" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"

  # pagination_token を使った後続のリクエスト
  curl "https://api.x.com/2/users/123/muting?max_results=100&pagination_token=NEXT_TOKEN" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"
  ```

  ```python title="Python SDK" lines wrap icon="python" theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # SDK はページネーションを自動で処理します
  all_muted = []

  for page in client.users.get_muting(user_id="123", max_results=100):
      if page.data:
          all_muted.extend(page.data)

  print(f"Muted {len(all_muted)} users")
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

  async function getAllMutedUsers(userId) {
    const allMuted = [];

    // SDK はページネーションを自動で処理します
    const paginator = client.users.getMuting(userId, { maxResults: 100 });

    for await (const page of paginator) {
      if (page.data) {
        allMuted.push(...page.data);
      }
    }

    return allMuted;
  }

  // 使用例
  const muted = await getAllMutedUsers("123");
  console.log(`Muted ${muted.length} users`);
  ```
</CodeGroup>

<Card title="ページネーションガイド" icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-arrow-right.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=88e933002782dbdeb204043cedef033e" href="/x-api/fundamentals/pagination" width="24" height="24" data-path="icons/xds/icon-arrow-right.svg">
  ページネーションについて詳しく学ぶ
</Card>

***

## 挙動の違い

### ミュートとブロックの違い

| Feature          | ミュート            | ブロック         |
| :--------------- | :-------------- | :----------- |
| 相手の Post を見る     | 見えない (非表示)      | 見えない         |
| 相手があなたの Post を見る | 見える             | 見えない         |
| 相手があなたをフォロー      | フォローされる (フォロー可) | されない (削除される) |
| 相手が DM を送れる      | 送れる             | 送れない         |
| 通知の送信            | されない            | されない         |

<Tip>
  ミュートはプライベートです — ミュートされたユーザーへの通知はなく、相手はミュートされたことを知ることができません。
</Tip>

***

## エラー処理

| Status | Error             | Solution         |
| :----- | :---------------- | :--------------- |
| 400    | Invalid request   | user ID の形式を確認   |
| 401    | Unauthorized      | access token を確認 |
| 403    | Forbidden         | スコープと権限を確認       |
| 404    | Not Found         | ユーザーが存在しない       |
| 429    | Too Many Requests | 待機してから再試行        |

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="クイックスタート" icon="https://mintcdn.com/x-preview/oR-aRNyj1BKPJtxM/icons/xds/icon-rocket.svg?fit=max&auto=format&n=oR-aRNyj1BKPJtxM&q=85&s=b978d7a9225de31709efbbed5b84e92d" href="/x-api/users/mutes/quickstart/manage-mutes-quickstart" width="24" height="24" data-path="icons/xds/icon-rocket.svg">
    最初の mutes リクエストを行う
  </Card>

  <Card title="Blocks" icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-block.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=702a65b4001948aebcc42635b8e2eac7" href="/x-api/users/blocks/introduction" width="24" height="24" data-path="icons/xds/icon-block.svg">
    ミュートの代わりにユーザーをブロック
  </Card>

  <Card title="API リファレンス" icon="https://mintcdn.com/x-preview/ygI6sSJPehlc0qNT/icons/xds/icon-code.svg?fit=max&auto=format&n=ygI6sSJPehlc0qNT&q=85&s=488e23401b19225b89acc0136d242219" href="/x-api/users/get-muting" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの詳細ドキュメント
  </Card>

  <Card title="サンプルコード" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    動作するコード例
  </Card>
</CardGroup>
