> ## 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.

# 連携ガイド

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

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>;
};

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

***

## 認証

List lookup エンドポイントは複数の認証方式をサポートします:

| Method                                                                                                                         | Best for    | 非公開 List にアクセスできるか |
| :----------------------------------------------------------------------------------------------------------------------------- | :---------- | :----------------- |
| [OAuth 2.0 App-Only](/resources/fundamentals/authentication#oauth-2-0)                                                         | 公開 List データ | 不可                 |
| [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)                                                              | レガシー連携      | 可 (所有/フォロー中)       |

### リクエスト例

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/lists/84839422?\
  list.fields=description,member_count,follower_count,private" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # ID で List を取得
  response = client.lists.get(
      list_id="84839422",
      list_fields=["description", "member_count", "follower_count", "private"]
  )
  print(response.data)
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  const response = await client.lists.get("84839422", {
    listFields: ["description", "member_count", "follower_count", "private"],
  });
  console.log(response.data);
  ```
</CodeGroup>

***

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

| Method | Endpoint                                                   | Description        |
| :----- | :--------------------------------------------------------- | :----------------- |
| GET    | [`/2/lists/:id`](/x-api/lists/get-list-by-id)              | ID で List を取得      |
| GET    | [`/2/users/:id/owned_lists`](/x-api/users/get-owned-lists) | ユーザーが所有する List を取得 |

***

## Fields と expansions

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

```json theme={null}
{
  "data": {
    "id": "84839422",
    "name": "Tech News"
  }
}
```

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

<Accordion title="list.fields">
  | Field            | Description     |
  | :--------------- | :-------------- |
  | `created_at`     | List 作成のタイムスタンプ |
  | `description`    | List の説明        |
  | `follower_count` | フォロワー数          |
  | `member_count`   | メンバー数           |
  | `owner_id`       | 所有者の user ID    |
  | `private`        | List が非公開かどうか   |
</Accordion>

<Accordion title="user.fields (owner_id expansion が必要)">
  | Field               | Description   |
  | :------------------ | :------------ |
  | `username`          | 所有者の @ハンドル    |
  | `name`              | 所有者の表示名       |
  | `verified`          | 所有者の認証済みステータス |
  | `profile_image_url` | 所有者のアバター URL  |
</Accordion>

### expansions を使った例

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/lists/84839422?\
  list.fields=description,member_count,follower_count,owner_id&\
  expansions=owner_id&\
  user.fields=username,verified" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # 所有者の expansion 付きで List を取得
  response = client.lists.get(
      list_id="84839422",
      list_fields=["description", "member_count", "follower_count", "owner_id"],
      expansions=["owner_id"],
      user_fields=["username", "verified"]
  )

  print(response.data)
  print(response.includes)  # 所有者のユーザーオブジェクトが含まれます
  ```

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

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  const response = await client.lists.get("84839422", {
    listFields: ["description", "member_count", "follower_count", "owner_id"],
    expansions: ["owner_id"],
    userFields: ["username", "verified"],
  });

  console.log(response.data);
  console.log(response.includes); // 所有者のユーザーオブジェクトが含まれます
  ```
</CodeGroup>

### expansion 付きのレスポンス

```json title="レスポンス例" lines wrap icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-brackets.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=ed2428e77bab43e57800e1a590e982fa" theme={null}
{
  "data": {
    "id": "84839422",
    "name": "Tech News",
    "description": "Top tech journalists",
    "member_count": 50,
    "follower_count": 1250,
    "owner_id": "2244994945"
  },
  "includes": {
    "users": [
      {
        "id": "2244994945",
        "username": "XDevelopers",
        "verified": true
      }
    ]
  }
}
```

<Card title="Fields と expansions ガイド" icon="sliders" href="/x-api/fundamentals/fields">
  レスポンスのカスタマイズについて詳しく学ぶ
</Card>

***

## ページネーション

所有 List の取得時、結果はページネーションされます:

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

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

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

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

  for page in client.lists.get_user_owned_lists(user_id="123", max_results=100):
      if page.data:
          all_lists.extend(page.data)

  print(f"Found {len(all_lists)} lists")
  ```

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

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  async function getAllOwnedLists(userId) {
    const allLists = [];

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

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

    return allLists;
  }

  // 使用例
  const lists = await getAllOwnedLists("123");
  console.log(`Found ${lists.length} lists`);
  ```
</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>

***

## 非公開 List

* 非公開 List は所有者にのみ表示されます
* 非公開 List の詳細を取得するには、所有者として認証する必要があります
* `private` フィールドは、その List が非公開かどうかを示します

***

## エラー処理

| Status | Error             | Solution       |
| :----- | :---------------- | :------------- |
| 400    | Invalid request   | List ID の形式を確認 |
| 401    | Unauthorized      | 認証を確認          |
| 403    | Forbidden         | 非公開の List の可能性 |
| 404    | Not Found         | List が存在しない    |
| 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/lists/list-lookup/quickstart" width="24" height="24" data-path="icons/xds/icon-rocket.svg">
    最初の List lookup リクエストを行う
  </Card>

  <Card title="List Posts" icon="https://mintcdn.com/x-preview/ygI6sSJPehlc0qNT/icons/xds/icon-bulleted-list.svg?fit=max&auto=format&n=ygI6sSJPehlc0qNT&q=85&s=b9bf8323233df59c682b0fec8e3f88d5" href="/x-api/lists/list-tweets/introduction" width="24" height="24" data-path="icons/xds/icon-bulleted-list.svg">
    List から Post を取得
  </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/lists/get-list-by-id" 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>
