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

# ユーザー検索クイックスタート

> ID またはユーザー名でユーザーを検索する

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

このガイドでは、ユーザーを ID またはユーザー名で検索する方法を説明します。

<Note>
  **前提条件**

  始める前に、次のものを用意してください。

  * 承認済みの App を持つ [開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App のベアラートークン
</Note>

***

<div id="look-up-by-id">
  ## ID で取得
</div>

<div id="single-user">
  ### 単一のユーザー
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/2244994945?\
  user.fields=created_at,description,verified,public_metrics" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # ID でユーザーを取得する
  response = client.users.get(
      "2244994945",
      user_fields=["created_at", "description", "verified", "public_metrics"]
  )

  print(f"Name: {response.data.name}")
  print(f"Username: {response.data.username}")
  print(f"Followers: {response.data.public_metrics.followers_count}")
  ```

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

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

  // ID でユーザーを取得する
  const response = await client.users.get("2244994945", {
    userFields: ["created_at", "description", "verified", "public_metrics"],
  });

  console.log(`Name: ${response.data?.name}`);
  console.log(`Username: ${response.data?.username}`);
  console.log(`Followers: ${response.data?.public_metrics?.followers_count}`);
  ```
</CodeGroup>

<div id="response">
  ### レスポンス
</div>

```json theme={null}
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "XDevelopers",
    "created_at": "2013-12-14T04:35:55.000Z",
    "description": "The voice of the X developer community",
    "verified": true,
    "public_metrics": {
      "followers_count": 583423,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}
```

<div id="multiple-users">
  ### 複数のユーザー
</div>

一度に最大 100 ユーザーを取得できます:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users?\
  ids=2244994945,783214,6253282&\
  user.fields=username,verified" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # 複数のユーザーを ID で取得する
  response = client.users.get_users(
      ids=["2244994945", "783214", "6253282"],
      user_fields=["username", "verified"]
  )

  for user in response.data:
      print(f"{user.username} - Verified: {user.verified}")
  ```

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

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

  // 複数のユーザーを ID で取得する
  const response = await client.users.getUsers({
    ids: ["2244994945", "783214", "6253282"],
    userFields: ["username", "verified"],
  });

  response.data?.forEach((user) => {
    console.log(`${user.username} - Verified: ${user.verified}`);
  });
  ```
</CodeGroup>

***

<div id="look-up-by-username">
  ## ユーザー名で取得
</div>

### 単一ユーザー

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/by/username/XDevelopers?\
  user.fields=created_at,description,verified" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # ユーザー名でユーザーを取得
  response = client.users.get_by_username(
      "XDevelopers",
      user_fields=["created_at", "description", "verified"]
  )

  print(f"ID: {response.data.id}")
  print(f"Name: {response.data.name}")
  ```

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

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

  // ユーザー名でユーザーを取得
  const response = await client.users.getByUsername("XDevelopers", {
    userFields: ["created_at", "description", "verified"],
  });

  console.log(`ID: ${response.data?.id}`);
  console.log(`Name: ${response.data?.name}`);
  ```
</CodeGroup>

<div id="multiple-users">
  ### 複数のユーザー
</div>

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/by?\
  usernames=XDevelopers,X,elonmusk&\
  user.fields=created_at,verified" \
    -H "Authorization: Bearer $BEARER_TOKEN"
  ```

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

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # ユーザー名で複数のユーザーを取得する
  response = client.users.get_users_by_usernames(
      usernames=["XDevelopers", "X", "elonmusk"],
      user_fields=["created_at", "verified"]
  )

  for user in response.data:
      print(f"{user.username} - {user.created_at}")
  ```

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

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

  // ユーザー名で複数のユーザーを取得する
  const response = await client.users.getUsersByUsernames({
    usernames: ["XDevelopers", "X", "elonmusk"],
    userFields: ["created_at", "verified"],
  });

  response.data?.forEach((user) => {
    console.log(`${user.username} - ${user.created_at}`);
  });
  ```
</CodeGroup>

***

<div id="available-fields">
  ## 利用可能なフィールド
</div>

| フィールド               | 説明            |
| :------------------ | :------------ |
| `created_at`        | アカウント作成日      |
| `description`       | ユーザーの自己紹介     |
| `profile_image_url` | プロフィール画像のURL  |
| `verified`          | 認証状態          |
| `public_metrics`    | フォロー/フォロワー数   |
| `location`          | ユーザーが指定した位置情報 |
| `url`               | ユーザーのウェブサイト   |
| `protected`         | 非公開アカウントかどうか  |
| `pinned_tweet_id`   | ピン留めされたポストのID |

***

<div id="handle-errors">
  ## エラーを処理する
</div>

<div id="user-not-found">
  ### ユーザーが見つかりません
</div>

```json theme={null}
{
  "errors": [
    {
      "resource_type": "user",
      "title": "Not Found Error",
      "detail": "Could not find user with username: [nonexistent_user]."
    }
  ]
}
```

<div id="protected-user">
  ### 保護されたユーザー
</div>

保護されたユーザーのデータも返されますが、そのユーザーをフォローしていない限り、そのユーザーのポストにはアクセスできません。

***

<div id="next-steps">
  ## 次のステップ
</div>

<CardGroup cols={2}>
  <Card title="認証済みユーザー" icon="user-check" href="/ja/x-api/users/lookup/quickstart/authenticated-lookup">
    現在のユーザーを取得する
  </Card>

  <Card title="統合ガイド" icon="book" href="/ja/x-api/users/lookup/integrate">
    基本概念とベストプラクティス
  </Card>

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