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

# クイックスタート

> このガイドでは、X API v2 を使用して最初の Post lookup リクエストを行う手順を説明します。lookup を扱う X API v2 スタンダードティアのリファレンス。

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

このガイドでは、X API v2 を使用して最初の Post lookup リクエストを行う手順を説明します。

<Note>
  **前提条件**

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

  * 承認済みの App を含む[開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * App の Bearer Token(Developer Console の「Keys and tokens」で確認できます)
</Note>

***

<Steps>
  <Step title="投稿 ID を見つける">
    すべての投稿には一意の ID があります。投稿の URL から確認できます:

    ```
    https://x.com/XDevelopers/status/1228393702244134912
                                    └── これが投稿 ID
    ```
  </Step>

  <Step title="リクエストを実行する">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/1228393702244134912" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

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

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # ID で単一の投稿を取得
      response = client.posts.get("1228393702244134912")
      print(response.data)
      ```

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

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

      const response = await client.posts.get("1228393702244134912");
      console.log(response.data);
      ```
    </CodeGroup>
  </Step>

  <Step title="レスポンスを確認する">
    デフォルトレスポンスには投稿の `id`、`text`、`edit_history_tweet_ids` が含まれます:

    ```json theme={null}
    {
      "data": {
        "id": "1228393702244134912",
        "text": "What did the developer write in their Valentine's card?\n\nwhile(true) {\n    I = Love(You);\n}",
        "edit_history_tweet_ids": ["1228393702244134912"]
      }
    }
    ```
  </Step>

  <Step title="追加フィールドをリクエストする">
    クエリパラメーターを使ってより多くのデータを取得します:

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/1228393702244134912?\
      tweet.fields=created_at,public_metrics,author_id&\
      expansions=author_id&\
      user.fields=username,verified" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

      ```python title="Python SDK" lines wrap icon="python" theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # 追加フィールドと expansions 付きで投稿を取得
      response = client.posts.get(
          "1228393702244134912",
          tweet_fields=["created_at", "public_metrics", "author_id"],
          expansions=["author_id"],
          user_fields=["username", "verified"]
      )

      print(response.data)
      print(response.includes)  # 作成者のユーザーオブジェクトを含む
      ```

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
      import { Client } from "@xdevplatform/xdk";

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

      const response = await client.posts.get("1228393702244134912", {
        tweetFields: ["created_at", "public_metrics", "author_id"],
        expansions: ["author_id"],
        userFields: ["username", "verified"],
      });

      console.log(response.data);
      console.log(response.includes); // 作成者のユーザーオブジェクトを含む
      ```
    </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": "1228393702244134912",
        "text": "What did the developer write in their Valentine's card?...",
        "created_at": "2020-02-14T19:00:55.000Z",
        "author_id": "2244994945",
        "public_metrics": {
          "retweet_count": 156,
          "reply_count": 23,
          "like_count": 892,
          "quote_count": 12
        },
        "edit_history_tweet_ids": ["1228393702244134912"]
      },
      "includes": {
        "users": [
          {
            "id": "2244994945",
            "username": "XDevelopers",
            "verified": true
          }
        ]
      }
    }
    ```
  </Step>

  <Step title="複数の投稿を取得する">
    1 回のリクエストで最大 100 件の投稿を取得します:

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets?\
      ids=1228393702244134912,1227640996038684673,1199786642791452673&\
      tweet.fields=created_at,author_id" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

      ```python title="Python SDK" lines wrap icon="python" theme={null}
      from xdk import Client

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # ID を指定して複数の投稿を取得
      response = client.posts.get_posts(
          ids=["1228393702244134912", "1227640996038684673", "1199786642791452673"],
          tweet_fields=["created_at", "author_id"]
      )

      for post in response.data:
          print(f"{post.id}: {post.text[:50]}...")
      ```

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
      import { Client } from "@xdevplatform/xdk";

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

      const response = await client.posts.getPosts({
        ids: ["1228393702244134912", "1227640996038684673", "1199786642791452673"],
        tweetFields: ["created_at", "author_id"],
      });

      response.data?.forEach((post) => {
        console.log(`${post.id}: ${post.text?.slice(0, 50)}...`);
      });
      ```
    </CodeGroup>
  </Step>
</Steps>

***

## 次のステップ

<CardGroup cols={2}>
  <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/posts/lookup/integrate" width="24" height="24" data-path="icons/xds/icon-book.svg">
    認証、レート制限、ベストプラクティスを学ぶ
  </Card>

  <Card title="Fields と expansions" icon="sliders" href="/x-api/fundamentals/fields">
    fields と expansions の仕組みをマスター
  </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/posts/get-post-by-id" width="24" height="24" data-path="icons/xds/icon-code.svg">
    利用可能なすべてのパラメーターを見る
  </Card>

  <Card title="サンプルコード" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    さらに多くの例を確認
  </Card>
</CardGroup>
