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

# Inicio rápido

> Crear y eliminar Publicaciones con la 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>;
};

Esta guía explica cómo crear y eliminar Publicaciones con la X API.

<Note>
  **Requisitos previos**

  Antes de comenzar, necesitarás:

  * Una [cuenta de desarrollador](https://developer.x.com/en/portal/petition/essential/basic-info) con una App aprobada
  * Tokens de acceso de usuario (OAuth 1.0a u OAuth 2.0 PKCE)
</Note>

***

<div id="create-a-post">
  ## Crear una Publicación
</div>

<Steps>
  <Step title="Prepara tu solicitud">
    El endpoint POST `/2/tweets` requiere un cuerpo JSON con al menos `text` o `media`:

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

  <Step title="Envía la solicitud">
    <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)

      # Crear una Publicación
      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 });

      // Crear una Publicación
      const response = await client.posts.create({ text: "Hello from the X API!" });
      console.log(`Created Post: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Revisa la respuesta">
    Una respuesta exitosa incluye los campos `id` y `text` de la nueva Publicación:

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

***

<div id="advanced-examples">
  ## Ejemplos avanzados
</div>

<AccordionGroup>
  <Accordion title="Responder a una publicación">
    <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": "This is a reply!",
          "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)

      # Crear una respuesta
      response = client.posts.create(
          text="This is a reply!",
          reply={"in_reply_to_tweet_id": "1234567890"}
      )
      print(f"Respuesta creada: {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 });

      // Crear una respuesta
      const response = await client.posts.create({
        text: "This is a reply!",
        reply: { inReplyToTweetId: "1234567890" },
      });
      console.log(`Respuesta creada: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Citar una publicación">
    <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": "¡Mira esto!",
          "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)

      # Citar una Publicación
      response = client.posts.create(
          text="¡Mira esto!",
          quote_tweet_id="1234567890"
      )
      print(f"Cita creada: {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 });

      // Citar una Publicación
      const response = await client.posts.create({
        text: "¡Mira esto!",
        quoteTweetId: "1234567890",
      });
      console.log(`Cita creada: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Publicación con medios">
    First, upload media using the [Media Upload endpoint](/es/x-api/media/quickstart/media-upload-chunked), then reference the `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 of the day!",
          "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)

      # Publicación con contenido multimedia
      response = client.posts.create(
          text="Photo of the day!",
          media={"media_ids": ["1234567890123456789"]}
      )
      print(f"Publicación creada con contenido multimedia: {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 });

      // Publicación con contenido multimedia
      const response = await client.posts.create({
        text: "Photo of the day!",
        media: { mediaIds: ["1234567890123456789"] },
      });
      console.log(`Publicación creada con contenido multimedia: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Publicación con encuesta">
    <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": "¿Cuál es tu color favorito?",
          "poll": {
            "options": ["Rojo", "Azul", "Verde", "Amarillo"],
            "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)

      # Publicación con encuesta
      response = client.posts.create(
          text="¿Cuál es tu color favorito?",
          poll={"options": ["Rojo", "Azul", "Verde", "Amarillo"], "duration_minutes": 1440}
      )
      print(f"Encuesta creada: {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 });

      // Publicación con encuesta
      const response = await client.posts.create({
        text: "¿Cuál es tu color favorito?",
        poll: { options: ["Rojo", "Azul", "Verde", "Amarillo"], durationMinutes: 1440 },
      });
      console.log(`Encuesta creada: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

***

<div id="delete-a-post">
  ## Eliminar una Publicación
</div>

<Steps>
  <Step title="Obtener el identificador de la Publicación">
    Necesitas el identificador de la Publicación que quieres eliminar. Este se obtiene cuando creas una Publicación.
  </Step>

  <Step title="Enviar una solicitud 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)

      # Eliminar una Publicación
      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 });

      // Eliminar una Publicación
      const response = await client.posts.delete("1445880548472328192");
      console.log(`Deleted: ${response.data?.deleted}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Confirmar la eliminación">
    ```json theme={null}
    {
      "data": {
        "deleted": true
      }
    }
    ```
  </Step>
</Steps>

<Warning>
  Solo puedes eliminar Publicaciones que tú hayas creado.
</Warning>

***

<div id="next-steps">
  ## Próximos pasos
</div>

<CardGroup cols={2}>
  <Card title="Guía de integración" icon="book" href="/es/x-api/posts/manage-tweets/integrate">
    Conceptos clave y prácticas recomendadas
  </Card>

  <Card title="Carga de medios" icon="image" href="/es/x-api/media/quickstart/media-upload-chunked">
    Sube contenido multimedia para Publicaciones
  </Card>

  <Card title="Referencia de la API" icon="code" href="/es/x-api/posts/create-post">
    Documentación completa del endpoint
  </Card>

  <Card title="Código de ejemplo" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    Ejemplos de código listos para usar
  </Card>
</CardGroup>
