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

# Démarrage rapide de la recherche récente

> Effectuez votre première requête de recherche récente en quelques minutes

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

Ce guide vous accompagne pas à pas pour effectuer votre première requête de recherche récente afin de trouver des Publications des 7 derniers jours.

<Note>
  **Prérequis**

  Avant de commencer, vous aurez besoin de :

  * D'un [compte développeur](https://developer.x.com/en/portal/petition/essential/basic-info) avec une App approuvée
  * Du Jeton Bearer de votre App (disponible dans la Console de développement sous « Keys and tokens »)
</Note>

***

<Steps>
  <Step title="Créer une requête" icon="magnifying-glass">
    Les requêtes de recherche utilisent des opérateurs pour cibler des Publications. Commencez par un mot-clé simple :

    ```
    python
    ```

    Ou combinez plusieurs opérateurs :

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

    Cette requête renvoie les Publications contenant "python" en anglais, en excluant les retweets.

    <Tip>
      Consultez la [référence complète des opérateurs](/fr/x-api/posts/search/integrate/operators) pour toutes les options disponibles.
    </Tip>
  </Step>

  <Step title="Effectuer une requête" 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")

      # Rechercher des publications récentes
      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" });

      // Rechercher des publications récentes
      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="Examinez la réponse" icon="eye">
    La réponse par défaut inclut `id`, `text` et `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="Ajouter des champs et des expansions" icon="sliders">
    Demandez des données supplémentaires à l'aide de paramètres de requête :

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

      # Recherche avec des champs et des 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" });

      // Recherche avec des champs et des 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>

    **Réponse :**

    ```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="Paginer les résultats" icon="arrow-right">
    Les SDK gèrent automatiquement la pagination. Pour cURL, utilisez le `next_token` dans la réponse :

    ```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="Guide de pagination" icon="arrow-right" href="/fr/x-api/posts/search/integrate/paginate">
      Découvrez comment parcourir de grands ensembles de résultats
    </Card>
  </Step>
</Steps>

***

<div id="example-queries">
  ## Exemples de requêtes
</div>

<AccordionGroup>
  <Accordion title="Publications d’un utilisateur spécifique">
    ```
    from:XDevelopers
    ```
  </Accordion>

  <Accordion title="Publications avec un hashtag">
    ```
    #Python -is:retweet
    ```
  </Accordion>

  <Accordion title="Publications contenant des images">
    ```
    "machine learning" has:images lang:en
    ```
  </Accordion>

  <Accordion title="Publications mentionnant un utilisateur">
    ```
    @elonmusk -is:retweet -is:reply
    ```
  </Accordion>

  <Accordion title="Publications contenant des liens vers un domaine">
    ```
    url:github.com lang:en
    ```
  </Accordion>
</AccordionGroup>

***

<div id="next-steps">
  ## Prochaines étapes
</div>

<CardGroup cols={2}>
  <Card title="Créer une requête" icon="magnifying-glass" href="/fr/x-api/posts/search/integrate/build-a-query">
    Maîtrisez la syntaxe des requêtes et les opérateurs
  </Card>

  <Card title="Référence des opérateurs" icon="list-check" href="/fr/x-api/posts/search/integrate/operators">
    Consultez tous les opérateurs disponibles
  </Card>

  <Card title="Recherche dans l’archive complète" icon="vault" href="/fr/x-api/posts/search/quickstart/full-archive-search">
    Recherchez dans l’archive complète des Publications
  </Card>

  <Card title="Référence de l’API" icon="code" href="/fr/x-api/posts/search-recent-posts">
    Documentation complète de l’endpoint
  </Card>
</CardGroup>
