このガイドでは、/me エンドポイントを使用して、現在認証されているユーザーのプロフィールを取得する方法を説明します。
前提条件始める前に、次のものが必要です。
- 承認済みの App を持つ開発者アカウント
- ユーザーアクセストークン (OAuth 1.0a または OAuth 2.0 PKCE)
User Access Token を使用して /me エンドポイントにリクエストを送信します。
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"
{
"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 エンドポイントは次のような場合に不可欠です:
- 認証の確認 — ユーザーが正しく認証されていることを確認する
- ユーザー ID の取得 — 他の API 呼び出しのために認証済みユーザーの ID を取得する
- エクスペリエンスのパーソナライズ — アプリ内でユーザーのプロフィールを表示する
- 代理でのリクエスト — どのユーザーの代理としてリクエストを行っているか把握する
ユーザーの固定されたポストを取得します:
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"
{
"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 | ユーザーの自己紹介 |
profile_image_url | プロフィール画像のURL |
verified | 認証ステータス |
public_metrics | フォロワー数/フォロー数 |
location | ユーザーが設定した場所 |
url | ユーザーのウェブサイト |
protected | 保護されたアカウントかどうか |
pinned_tweet_id | 固定されたポストのID |
/me エンドポイントには User Context 認証が必要です。App-Only (ベアラートークン) 認証は利用できません。
次のいずれかを使用してください。
APIリファレンス
エンドポイントの完全なリファレンス