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

# Recent Search Quickstart

> This guide walks you through making your first recent search request to find Posts from the. Reference for the X API v2 standard tier covering quickstart.

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

This guide walks you through making your first recent search request to find Posts from the last 7 days.

<Note>
  **Prerequisites**

  Before you begin, you'll need:

  * A [developer account](https://developer.x.com/en/portal/petition/essential/basic-info) with an approved App
  * Your App's Bearer Token (found in the Developer Console under "Keys and tokens")
</Note>

***

<Steps>
  <Step title="Build a query" icon="magnifying-glass">
    Search queries use operators to match Posts. Start with a simple keyword:

    ```
    python
    ```

    Or combine multiple operators:

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

    This matches Posts containing "python" in English, excluding retweets.

    <Tip>
      See the [full operator reference](/x-api/posts/search/integrate/operators) for all available options.
    </Tip>
  </Step>

  <Step title="Make a request" 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")

      # Search recent Posts
      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" });

      // Search recent Posts
      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="Review the response" icon="eye">
    The default response includes `id`, `text`, and `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="Add fields and expansions" icon="sliders">
    Request additional data with query parameters:

    <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")

      # Search with fields and 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" });

      // Search with fields and 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>

    **Response:**

    ```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="Paginate through results" icon="arrow-right">
    The SDKs handle pagination automatically. For cURL, use the `next_token` from the response:

    ```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="Pagination guide" icon="arrow-right" href="/x-api/posts/search/integrate/paginate">
      Learn more about navigating large result sets
    </Card>
  </Step>
</Steps>

***

## Example queries

<AccordionGroup>
  <Accordion title="Posts from a specific user">
    ```
    from:XDevelopers
    ```
  </Accordion>

  <Accordion title="Posts with a hashtag">
    ```
    #Python -is:retweet
    ```
  </Accordion>

  <Accordion title="Posts with images">
    ```
    "machine learning" has:images lang:en
    ```
  </Accordion>

  <Accordion title="Posts mentioning a user">
    ```
    @elonmusk -is:retweet -is:reply
    ```
  </Accordion>

  <Accordion title="Posts with links to a domain">
    ```
    url:github.com lang:en
    ```
  </Accordion>
</AccordionGroup>

***

## Next steps

<CardGroup cols={2}>
  <Card title="Build a query" icon="magnifying-glass" href="/x-api/posts/search/integrate/build-a-query">
    Master query syntax and operators
  </Card>

  <Card title="Operator reference" icon="list-check" href="/x-api/posts/search/integrate/operators">
    See all available operators
  </Card>

  <Card title="Full-archive search" icon="vault" href="/x-api/posts/search/quickstart/full-archive-search">
    Search the complete Post archive
  </Card>

  <Card title="API Reference" icon="code" href="/x-api/posts/search-recent-posts">
    Full endpoint documentation
  </Card>
</CardGroup>
