> ## 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 Members Lookup

> X API v2 の List members lookup エンドポイントを利用して X の List のメンバーを取得するクイックスタート。認証方法とリクエスト例を含みます。

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 のメンバーを取得する手順を説明します。

<Note>
  **前提条件**

  始める前に、以下が必要です:

  * 承認済みの App がある [developer account](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App の Bearer Token
</Note>

***

## List のメンバーを取得

<Steps>
  <Step title="List ID を確認">
    List 表示時の URL から List ID を確認できます:

    ```
    https://x.com/i/lists/84839422
                          └── これが List ID
    ```
  </Step>

  <Step title="List のメンバーをリクエスト">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/lists/84839422/members?\
      user.fields=created_at,username,verified&\
      max_results=100" \
        -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")

      # ページネーションで List のメンバーを取得
      for page in client.lists.get_members(
          "84839422",
          user_fields=["created_at", "username", "verified"],
          max_results=100
      ):
          for user in page.data:
              print(f"{user.username} - Joined: {user.created_at}")
      ```

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

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

      // ページネーションで List のメンバーを取得
      const paginator = client.lists.getMembers("84839422", {
        userFields: ["created_at", "username", "verified"],
        maxResults: 100,
      });

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

  <Step title="レスポンスを確認">
    ```json theme={null}
    {
      "data": [
        {
          "id": "1319036828964454402",
          "name": "Birdwatch",
          "username": "birdwatch",
          "created_at": "2020-10-21T22:04:47.000Z",
          "verified": true
        },
        {
          "id": "1065249714214457345",
          "name": "Spaces",
          "username": "TwitterSpaces",
          "created_at": "2018-11-21T14:24:58.000Z",
          "verified": true
        }
      ],
      "meta": {
        "result_count": 2,
        "next_token": "5349804505549807616"
      }
    }
    ```
  </Step>
</Steps>

***

## 追加データを含める

expansions を使うと、pinned Post などの関連データを取得できます:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/lists/84839422/members?\
  user.fields=created_at&\
  expansions=pinned_tweet_id&\
  tweet.fields=created_at" \
    -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")

  # expansions つきで List のメンバーを取得
  for page in client.lists.get_members(
      "84839422",
      user_fields=["created_at"],
      expansions=["pinned_tweet_id"],
      tweet_fields=["created_at"]
  ):
      for user in page.data:
          print(f"{user.username}")
      # ピン留めされた Post は page.includes.tweets にあります
  ```

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

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

  // expansions つきで List のメンバーを取得
  const paginator = client.lists.getMembers("84839422", {
    userFields: ["created_at"],
    expansions: ["pinned_tweet_id"],
    tweetFields: ["created_at"],
  });

  for await (const page of paginator) {
    page.data?.forEach((user) => {
      console.log(user.username);
    });
    // ピン留めされた Post は page.includes?.tweets にあります
  }
  ```
</CodeGroup>

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="Manage List members" icon="user-plus" href="/x-api/lists/list-members/quickstart/manage-list-members">
    メンバーの追加・削除
  </Card>

  <Card title="List lookup" 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-lookup/quickstart" width="24" height="24" data-path="icons/xds/icon-bulleted-list.svg">
    List の詳細を取得
  </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-members" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの詳細ドキュメント
  </Card>
</CardGroup>
