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

# 認証済みユーザーのクイックスタート

> このガイドでは、`/me` エンドポイントを使って現在認証されているユーザーのプロフィールを取得する手順を説明します。X API v2 スタンダード階層の quickstart に関するリファレンスドキュメントです。

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

このガイドでは、`/me` エンドポイントを使って現在認証されているユーザーのプロフィールを取得する手順を説明します。

<Note>
  **前提条件**

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

  * 承認済みの App がある [developer account](https://developer.x.com/en/portal/petition/essential/basic-info)
  * ユーザー Access Token (OAuth 1.0a または OAuth 2.0 PKCE)
</Note>

***

## 認証済みユーザーを取得

ユーザー Access Token を使って `/me` エンドポイントへリクエストします:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl "https://api.x.com/2/users/me?\
  user.fields=created_at,description,verified,public_metrics,profile_image_url" \
    -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")

  # 認証済みユーザーを取得
  response = client.users.get_me(
      user_fields=["created_at", "description", "verified", "public_metrics", "profile_image_url"]
  )

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

  ```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 response = await client.users.getMe({
    userFields: ["created_at", "description", "verified", "public_metrics", "profile_image_url"],
  });

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

***

## レスポンス

```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": "2244994945",
    "name": "X Developers",
    "username": "XDevelopers",
    "created_at": "2013-12-14T04:35:55.000Z",
    "description": "The voice of the X developer community",
    "verified": true,
    "profile_image_url": "https://pbs.twimg.com/profile_images/...",
    "public_metrics": {
      "followers_count": 583423,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}
```

***

## ユースケース

`/me` エンドポイントは以下の場面で不可欠です:

* **認証の確認** — ユーザーが適切に認証されていることを確認
* **user ID の取得** — 他の API 呼び出し用に認証済みユーザーの ID を取得
* **体験のパーソナライズ** — アプリでユーザーのプロフィールを表示
* **代理リクエスト** — 誰の代わりにリクエストを行っているかを把握

***

## ピン留めした Post を含める

ユーザーのピン留めした Post をリクエストします:

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

  # ピン留めした Post 付きで認証済みユーザーを取得
  response = client.users.get_me(
      user_fields=["pinned_tweet_id"],
      expansions=["pinned_tweet_id"],
      tweet_fields=["created_at", "text"]
  )

  print(f"Username: {response.data.username}")
  # ピン留めされた Post は response.includes.tweets にあります
  ```

  ```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" });

  // ピン留めした Post 付きで認証済みユーザーを取得
  const response = await client.users.getMe({
    userFields: ["pinned_tweet_id"],
    expansions: ["pinned_tweet_id"],
    tweetFields: ["created_at", "text"],
  });

  console.log(`Username: ${response.data?.username}`);
  // ピン留めされた Post は response.includes?.tweets にあります
  ```
</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": "2244994945",
    "name": "X Developers",
    "username": "XDevelopers",
    "pinned_tweet_id": "1234567890"
  },
  "includes": {
    "tweets": [
      {
        "id": "1234567890",
        "text": "Welcome to my profile!",
        "created_at": "2024-01-01T00:00:00.000Z"
      }
    ]
  }
}
```

***

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

| Field               | Description      |
| :------------------ | :--------------- |
| `created_at`        | アカウント作成日         |
| `description`       | ユーザーの bio        |
| `profile_image_url` | アバターの URL        |
| `verified`          | 認証済みステータス        |
| `public_metrics`    | フォロワー/フォロー中の件数   |
| `location`          | ユーザーが設定した所在地     |
| `url`               | ユーザーの Web サイト    |
| `protected`         | 非公開アカウントのステータス   |
| `pinned_tweet_id`   | ピン留めした Post の ID |

***

## 認証要件

<Warning>
  `/me` エンドポイントは User Context 認証が必要です。App-Only (Bearer Token) 認証はサポートされていません。
</Warning>

いずれかを利用してください:

* [OAuth 1.0a User Context](/resources/fundamentals/authentication)
* [OAuth 2.0 Authorization Code with PKCE](/resources/fundamentals/authentication#oauth-2-0-authorization-code-flow-with-pkce-2)

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="User lookup" icon="https://mintcdn.com/x-preview/SxzTbJaLjs3MidH1/icons/xds/icon-people.svg?fit=max&auto=format&n=SxzTbJaLjs3MidH1&q=85&s=9d5f3f82edcd2a4070364193436e7980" href="/x-api/users/lookup/quickstart/user-lookup" width="24" height="24" data-path="icons/xds/icon-people.svg">
    他のユーザーをルックアップ
  </Card>

  <Card title="連携ガイド" icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-book.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=22ac564792481d14ae36a941546039c8" href="/x-api/users/lookup/integrate" width="24" height="24" data-path="icons/xds/icon-book.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-my-user" width="24" height="24" data-path="icons/xds/icon-code.svg">
    エンドポイントの詳細ドキュメント
  </Card>
</CardGroup>
