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

> Créer et supprimer des Publications avec X API

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 explique comment créer et supprimer des Publications à l'aide de la X API.

<Note>
  **Prérequis**

  Avant de commencer, vous aurez besoin :

  * d'un [compte développeur](https://developer.x.com/en/portal/petition/essential/basic-info) avec une App approuvée
  * de jetons d'accès utilisateur (OAuth 1.0a ou OAuth 2.0 PKCE)
</Note>

***

<div id="create-a-post">
  ## Créer une Publication
</div>

<Steps>
  <Step title="Préparer votre requête">
    Le point de terminaison POST `/2/tweets` nécessite un corps JSON contenant au minimum `text` ou `media` :

    ```json theme={null}
    {
      "text": "Hello from the X API!"
    }
    ```
  </Step>

  <Step title="Envoyer la requête">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"text": "Hello from the X API!"}'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Créer une Publication
      response = client.posts.create(text="Hello from the X API!")
      print(f"Created Post: {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Créer une Publication
      const response = await client.posts.create({ text: "Hello from the X API!" });
      console.log(`Created Post: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Vérifier la réponse">
    Une réponse réussie contient l’`id` et le champ `text` de la nouvelle Publication :

    ```json theme={null}
    {
      "data": {
        "id": "1445880548472328192",
        "text": "Hello from the X API!"
      }
    }
    ```
  </Step>
</Steps>

***

<div id="advanced-examples">
  ## Exemples avancés
</div>

<AccordionGroup>
  <Accordion title="Répondre à une publication">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Ceci est une réponse !",
          "reply": {
            "in_reply_to_tweet_id": "1234567890"
          }
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Créer une réponse
      response = client.posts.create(
          text="Ceci est une réponse !",
          reply={"in_reply_to_tweet_id": "1234567890"}
      )
      print(f"Réponse créée : {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Créer une réponse
      const response = await client.posts.create({
        text: "Ceci est une réponse !",
        reply: { inReplyToTweetId: "1234567890" },
      });
      console.log(`Réponse créée : ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Citer une publication">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Regardez ça !",
          "quote_tweet_id": "1234567890"
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Citer une Publication
      response = client.posts.create(
          text="Regardez ça !",
          quote_tweet_id="1234567890"
      )
      print(f"Citation créée : {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Citer une Publication
      const response = await client.posts.create({
        text: "Regardez ça !",
        quoteTweetId: "1234567890",
      });
      console.log(`Citation créée : ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Publication avec média intégré">
    Commencez par téléverser le média à l’aide du [point de terminaison Media Upload](/fr/x-api/media/quickstart/media-upload-chunked), puis référencez le `media_id` :

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Photo du jour !",
          "media": {
            "media_ids": ["1234567890123456789"]
          }
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Publication avec média
      response = client.posts.create(
          text="Photo du jour !",
          media={"media_ids": ["1234567890123456789"]}
      )
      print(f"Publication avec média créée : {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Publication avec média
      const response = await client.posts.create({
        text: "Photo du jour !",
        media: { mediaIds: ["1234567890123456789"] },
      });
      console.log(`Publication avec média créée : ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Publication contenant un sondage">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Quelle est votre couleur préférée ?",
          "poll": {
            "options": ["Rouge", "Bleu", "Vert", "Jaune"],
            "duration_minutes": 1440
          }
        }'
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Publication avec sondage
      response = client.posts.create(
          text="Quelle est votre couleur préférée ?",
          poll={"options": ["Rouge", "Bleu", "Vert", "Jaune"], "duration_minutes": 1440}
      )
      print(f"Sondage créé : {response.data.id}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Publication avec sondage
      const response = await client.posts.create({
        text: "Quelle est votre couleur préférée ?",
        poll: { options: ["Rouge", "Bleu", "Vert", "Jaune"], durationMinutes: 1440 },
      });
      console.log(`Sondage créé : ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

***

<div id="delete-a-post">
  ## Supprimer une Publication
</div>

<Steps>
  <Step title="Obtenir l’identifiant de la Publication">
    Vous avez besoin de l’identifiant de la Publication que vous souhaitez supprimer. Celui-ci vous est renvoyé lorsque vous créez une Publication.
  </Step>

  <Step title="Envoyer une requête DELETE">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X DELETE "https://api.x.com/2/tweets/1445880548472328192" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN"
      ```

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

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Supprimer une Publication
      response = client.posts.delete("1445880548472328192")
      print(f"Deleted: {response.data.deleted}")
      ```

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

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Supprimer une Publication
      const response = await client.posts.delete("1445880548472328192");
      console.log(`Deleted: ${response.data?.deleted}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Confirmer la suppression">
    ```json theme={null}
    {
      "data": {
        "deleted": true
      }
    }
    ```
  </Step>
</Steps>

<Warning>
  Vous pouvez uniquement supprimer les Publications que vous avez créées.
</Warning>

***

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

<CardGroup cols={2}>
  <Card title="Guide d’intégration" icon="book" href="/fr/x-api/posts/manage-tweets/integrate">
    Concepts clés et bonnes pratiques
  </Card>

  <Card title="Téléversement de médias" icon="image" href="/fr/x-api/media/quickstart/media-upload-chunked">
    Importez des médias pour vos Publications
  </Card>

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

  <Card title="Exemples de code" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    Exemples de code prêts à l’emploi
  </Card>
</CardGroup>
