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

# Gestionar Retweets

> Retuitea y deshaz Retweets usando 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 te explica cómo hacer Retweets y deshacerlos usando 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
  * Token de acceso de usuario (OAuth 1.0a o OAuth 2.0 PKCE)
</Note>

***

<div id="retweet-a-post">
  ## Retuitear una Publicación
</div>

<Steps>
  <Step title="Obtén tu ID de usuario">
    Necesitas el ID del usuario autenticado. Puedes encontrarlo usando el [endpoint de búsqueda de usuarios](/es/x-api/users/lookup/introduction) o a partir de tu token de acceso (la parte numérica es tu ID de usuario).
  </Step>

  <Step title="Obtén el ID de la Publicación">
    Busca el ID de la publicación en la URL cuando veas una publicación:

    ```
    https://x.com/XDevelopers/status/1228393702244134912
                                    └── Este es el ID de la publicación
    ```
  </Step>

  <Step title="Envía la solicitud de Retweet">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/users/123456789/retweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"tweet_id": "1228393702244134912"}'
      ```

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

      # Retweet a Post
      response = client.posts.retweet(
          user_id="123456789",
          tweet_id="1228393702244134912"
      )

      print(f"Retweeted: {response.data.retweeted}")
      ```

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

      // Retweet a Post
      const response = await client.posts.retweet("123456789", {
        tweetId: "1228393702244134912",
      });

      console.log(`Retweeted: ${response.data?.retweeted}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Revisa la respuesta">
    ```json theme={null}
    {
      "data": {
        "retweeted": true
      }
    }
    ```
  </Step>
</Steps>

***

<div id="undo-a-retweet">
  ## Deshacer un Retweet
</div>

Quitar un Retweet:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.x.com/2/users/123456789/retweets/1228393702244134912" \
    -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)

  # Deshacer un Retweet
  response = client.posts.unretweet(
      user_id="123456789",
      tweet_id="1228393702244134912"
  )

  print(f"Retweeted: {response.data.retweeted}")
  ```

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

  // Deshacer un Retweet
  const response = await client.posts.unretweet("123456789", "1228393702244134912");

  console.log(`Retweeted: ${response.data?.retweeted}`);
  ```
</CodeGroup>

**Respuesta:**

```json theme={null}
{
  "data": {
    "retweeted": false
  }
}
```

***

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

<CardGroup cols={2}>
  <Card title="Búsqueda de Retweets" icon="retweet" href="/es/x-api/posts/retweets/quickstart/retweets-lookup">
    Obtén a los usuarios que hicieron Retweet de una Publicación
  </Card>

  <Card title="Publicaciones citadas" icon="quote-left" href="/es/x-api/posts/quote-tweets/quickstart">
    Obtén Publicaciones con cita
  </Card>

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