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

# Fields

> X API v2 はデフォルトで最小限のデータを返します。fields パラメータを使用して、各オブジェクトタイプの追加データをリクエストしてください。デフォルトでは post lookup は次のみを返します。

X API v2 はデフォルトで最小限のデータを返します。各オブジェクトタイプの追加データをリクエストするには **fields パラメータ** を使用します。

***

## Fields の仕組み

デフォルトでは、post lookup は `id`、`text`、`edit_history_tweet_ids` のみを返します。より多くのデータを取得するには、リクエストに fields パラメータを追加します。

```bash theme={null}
# デフォルトのレスポンス - 最小限のフィールド
curl "https://api.x.com/2/tweets/1234567890" \
  -H "Authorization: Bearer $TOKEN"

# 追加のフィールドを指定
curl "https://api.x.com/2/tweets/1234567890?tweet.fields=created_at,public_metrics,author_id" \
  -H "Authorization: Bearer $TOKEN"
```

***

## 利用可能な fields パラメータ

各オブジェクトタイプには専用の fields パラメータがあります。

| Object       | Parameter      | Documentation                                                       |
| :----------- | :------------- | :------------------------------------------------------------------ |
| Post (Tweet) | `tweet.fields` | [Post fields](/x-api/fundamentals/data-dictionary/reference#tweet)  |
| User         | `user.fields`  | [User fields](/x-api/fundamentals/data-dictionary/reference#user)   |
| Media        | `media.fields` | [Media fields](/x-api/fundamentals/data-dictionary/reference#media) |
| Poll         | `poll.fields`  | [Poll fields](/x-api/fundamentals/data-dictionary/reference#poll)   |
| Place        | `place.fields` | [Place fields](/x-api/fundamentals/data-dictionary/reference#place) |

***

## 例: Post fields

`tweet.fields` を使用して特定の post フィールドをリクエストします。

```bash theme={null}
curl "https://api.x.com/2/tweets/1234567890?tweet.fields=created_at,public_metrics,lang" \
  -H "Authorization: Bearer $TOKEN"
```

レスポンス:

```json title="Example response" 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": "1234567890",
    "text": "Hello world!",
    "edit_history_tweet_ids": ["1234567890"],
    "created_at": "2024-01-15T12:00:00.000Z",
    "lang": "en",
    "public_metrics": {
      "retweet_count": 10,
      "reply_count": 5,
      "like_count": 100,
      "quote_count": 2,
      "bookmark_count": 3,
      "impression_count": 1500
    }
  }
}
```

***

## 例: User fields

`user.fields` を使用して特定のユーザーフィールドをリクエストします。

```bash theme={null}
curl "https://api.x.com/2/users/by/username/xdevelopers?user.fields=created_at,description,public_metrics" \
  -H "Authorization: Bearer $TOKEN"
```

レスポンス:

```json title="Example response" 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 Platform",
    "public_metrics": {
      "followers_count": 570842,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}
```

***

## 関連オブジェクトの fields

関連オブジェクトのフィールド（post の作者など）を取得するには、次の 2 つが必要です。

1. 関連オブジェクトを含めるための **expansion**
2. そのオブジェクトタイプの **fields パラメータ**

```bash theme={null}
# 作者の詳細付きで post を取得
curl "https://api.x.com/2/tweets/1234567890?expansions=author_id&user.fields=description,public_metrics" \
  -H "Authorization: Bearer $TOKEN"
```

レスポンス:

```json title="Example response" 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": "1234567890",
    "text": "Hello world!",
    "author_id": "2244994945"
  },
  "includes": {
    "users": [{
      "id": "2244994945",
      "name": "X Developers",
      "username": "xdevelopers",
      "description": "The voice of the X Developer Platform",
      "public_metrics": {
        "followers_count": 570842,
        "following_count": 2048
      }
    }]
  }
}
```

[expansions の詳細を見る →](/x-api/fundamentals/expansions)

***

## 一般的な fields の組み合わせ

<Tabs>
  <Tab title="Post 分析">
    ```
    tweet.fields=created_at,public_metrics,possibly_sensitive
    ```
  </Tab>

  <Tab title="User プロフィール">
    ```
    user.fields=created_at,description,location,public_metrics,verified
    ```
  </Tab>

  <Tab title="完全な post コンテキスト">
    ```
    tweet.fields=created_at,author_id,conversation_id,in_reply_to_user_id,referenced_tweets
    expansions=author_id,referenced_tweets.id
    user.fields=username,name
    ```
  </Tab>

  <Tab title="メディアの詳細">
    ```
    tweet.fields=attachments
    expansions=attachments.media_keys
    media.fields=url,preview_image_url,alt_text,public_metrics
    ```
  </Tab>
</Tabs>

***

## 重要な注意事項

<Warning>
  **サブフィールドはリクエストできません。** `public_metrics` をリクエストすると、すべての metrics（likes、reposts、replies、quotes、bookmarks、impressions）が返されます。`public_metrics.like_count` のみをリクエストすることはできません。
</Warning>

* レスポンスのフィールド順序はリクエスト順序と異なる場合があります
* レスポンスに欠落しているフィールドは、値が `null` か空であることを意味します
* 一部のフィールドは特定の認証が必要です（例: private metrics は user context が必要）
* 利用可能なフィールドについては、各エンドポイントの API リファレンスを確認してください

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="Expansions" icon="expand" href="/x-api/fundamentals/expansions">
    レスポンスに関連オブジェクトを含める。
  </Card>

  <Card title="Data Dictionary" 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/fundamentals/data-dictionary" width="24" height="24" data-path="icons/xds/icon-book.svg">
    すべてのオブジェクトの完全なフィールドリファレンス。
  </Card>
</CardGroup>
