> ## Documentation Index
> Fetch the complete documentation index at: https://generaltranslation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 最近の検索クイックスタート

> 数分で最近の検索リクエストを初めて送信する

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <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>;
};

このガイドでは、過去 7 日間の投稿を検索するための recent search リクエストを初めて実行する手順を説明します。

<Note>
  **前提条件**

  始める前に、次のものが必要です。

  * 承認された App を持つ [開発者アカウント](https://developer.x.com/en/portal/petition/essential/basic-info)
  * 開発者コンソールの「Keys and tokens」で確認できる、App のベアラートークン
</Note>

***

<Steps>
  <Step title="クエリを作成" icon="magnifying-glass">
    検索クエリでは、投稿を絞り込むためにオペレーターを使用します。まずはシンプルなキーワードから始めましょう:

    ```
    python
    ```

    または、複数の演算子を組み合わせます：

    ```
    python lang:en -is:retweet
    ```

    これは、英語の投稿のうち本文に「python」を含み、リツイートを除外したものに一致します。

    <Tip>
      利用可能なすべてのオプションについては、[完全なオペレーターリファレンス](/ja/x-api/posts/search/integrate/operators)を参照してください。
    </Tip>
  </Step>

  <Step title="リクエストを送信する" icon="terminal">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/search/recent?query=python%20lang%3Aen%20-is%3Aretweet" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

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

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # 最近の投稿を検索
      for page in client.posts.search_recent(
          query="python lang:en -is:retweet"
      ):
          for post in page.data:
              print(post.text)
      ```

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

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

      // 最近の投稿を検索
      const paginator = client.posts.searchRecent({
        query: "python lang:en -is:retweet",
      });

      for await (const page of paginator) {
        page.data?.forEach((post) => {
          console.log(post.text);
        });
      }
      ```
    </CodeGroup>
  </Step>

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

    ```json theme={null}
    {
      "data": [
        {
          "id": "1234567890123456789",
          "text": "Just started learning Python and loving it!",
          "edit_history_tweet_ids": ["1234567890123456789"]
        },
        {
          "id": "1234567890123456788",
          "text": "Python tip: use list comprehensions for cleaner code",
          "edit_history_tweet_ids": ["1234567890123456788"]
        }
      ],
      "meta": {
        "newest_id": "1234567890123456789",
        "oldest_id": "1234567890123456788",
        "result_count": 2
      }
    }
    ```
  </Step>

  <Step title="フィールドとexpansionsを追加する" icon="sliders">
    クエリパラメータを指定して追加のデータをリクエストします:

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl "https://api.x.com/2/tweets/search/recent?\
      query=python%20lang%3Aen%20-is%3Aretweet&\
      tweet.fields=created_at,public_metrics,author_id&\
      expansions=author_id&\
      user.fields=username,verified&\
      max_results=10" \
        -H "Authorization: Bearer $BEARER_TOKEN"
      ```

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

      client = Client(bearer_token="YOUR_BEARER_TOKEN")

      # fields と expansions を指定して検索
      for page in client.posts.search_recent(
          query="python lang:en -is:retweet",
          tweet_fields=["created_at", "public_metrics", "author_id"],
          expansions=["author_id"],
          user_fields=["username", "verified"],
          max_results=10
      ):
          for post in page.data:
              print(f"{post.text[:50]}... - Likes: {post.public_metrics.like_count}")
      ```

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

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

      // fields と expansions を指定して検索
      const paginator = client.posts.searchRecent({
        query: "python lang:en -is:retweet",
        tweetFields: ["created_at", "public_metrics", "author_id"],
        expansions: ["author_id"],
        userFields: ["username", "verified"],
        maxResults: 10,
      });

      for await (const page of paginator) {
        page.data?.forEach((post) => {
          console.log(`${post.text?.slice(0, 50)}... - Likes: ${post.public_metrics?.like_count}`);
        });
      }
      ```
    </CodeGroup>

    **レスポンス：**

    ```json theme={null}
    {
      "data": [
        {
          "id": "1234567890123456789",
          "text": "Just started learning Python and loving it!",
          "created_at": "2024-01-15T10:30:00.000Z",
          "author_id": "9876543210",
          "public_metrics": {
            "retweet_count": 5,
            "reply_count": 2,
            "like_count": 42,
            "quote_count": 1
          },
          "edit_history_tweet_ids": ["1234567890123456789"]
        }
      ],
      "includes": {
        "users": [
          {
            "id": "9876543210",
            "username": "pythondev",
            "verified": false
          }
        ]
      },
      "meta": {
        "newest_id": "1234567890123456789",
        "oldest_id": "1234567890123456789",
        "result_count": 1
      }
    }
    ```
  </Step>

  <Step title="結果をページングする" icon="arrow-right">
    SDK はページネーションを自動処理します。cURL を使用する場合は、レスポンスの `next_token` を使用してください。

    ```bash theme={null}
    curl "https://api.x.com/2/tweets/search/recent?\
    query=python&\
    max_results=100&\
    next_token=b26v89c19zqg8o3fo7gesq314yb9l2l4ptqy" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```

    <Card title="ページネーションガイド" icon="arrow-right" href="/ja/x-api/posts/search/integrate/paginate">
      大規模な結果セットの扱い方について詳しく学ぶ
    </Card>
  </Step>
</Steps>

***

<div id="example-queries">
  ## クエリ例
</div>

<AccordionGroup>
  <Accordion title="特定のユーザーの投稿">
    ```
    from:XDevelopers
    ```
  </Accordion>

  <Accordion title="ハッシュタグが付いた投稿">
    ```
    #Python -is:retweet
    ```
  </Accordion>

  <Accordion title="画像付きの投稿">
    ```
    "machine learning" has:images lang:en
    ```
  </Accordion>

  <Accordion title="ユーザーへの言及を含む投稿">
    ```
    @elonmusk -is:retweet -is:reply
    ```
  </Accordion>

  <Accordion title="特定ドメインへのリンクを含む投稿">
    ```
    url:github.com lang:en
    ```
  </Accordion>
</AccordionGroup>

***

<div id="next-steps">
  ## 次のステップ
</div>

<CardGroup cols={2}>
  <Card title="クエリを作成する" icon="magnifying-glass" href="/ja/x-api/posts/search/integrate/build-a-query">
    クエリ構文とオペレーターをマスターする
  </Card>

  <Card title="オペレーターリファレンス" icon="list-check" href="/ja/x-api/posts/search/integrate/operators">
    利用可能なすべてのオペレーターを確認する
  </Card>

  <Card title="フルアーカイブ検索" icon="vault" href="/ja/x-api/posts/search/quickstart/full-archive-search">
    ポストの全アーカイブを検索する
  </Card>

  <Card title="APIリファレンス" icon="code" href="/ja/x-api/posts/search-recent-posts">
    エンドポイントの詳細ドキュメント
  </Card>
</CardGroup>
