メインコンテンツへスキップ
このガイドでは、ユーザーを ID またはユーザー名で検索する方法を説明します。
前提条件始める前に、次のものを用意してください。

ID で取得

単一のユーザー

cURL
curl "https://api.x.com/2/users/2244994945?\
user.fields=created_at,description,verified,public_metrics" \
  -H "Authorization: Bearer $BEARER_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,
    "public_metrics": {
      "followers_count": 583423,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}

複数のユーザー

一度に最大 100 ユーザーを取得できます:
cURL
curl "https://api.x.com/2/users?\
ids=2244994945,783214,6253282&\
user.fields=username,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"

ユーザー名で取得

単一ユーザー

cURL
curl "https://api.x.com/2/users/by/username/XDevelopers?\
user.fields=created_at,description,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"

複数のユーザー

cURL
curl "https://api.x.com/2/users/by?\
usernames=XDevelopers,X,elonmusk&\
user.fields=created_at,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"

利用可能なフィールド

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

エラーを処理する

ユーザーが見つかりません

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

保護されたユーザー

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

次のステップ

認証済みユーザー

現在のユーザーを取得する

統合ガイド

基本概念とベストプラクティス

APIリファレンス

エンドポイントの詳細ドキュメント