Skip to main content
This guide walks you through liking and unliking Posts using the X API.
PrerequisitesBefore you begin, you’ll need:
  • A developer account with an approved App
  • User Access Token (OAuth 1.0a or OAuth 2.0 PKCE)

Like a Post

1

Get your user ID

You need your authenticated user’s ID. You can find it using the user lookup endpoint or from your Access Token (the numeric part is your user ID).
2

Get the Post ID

Find the Post ID in the URL when viewing a Post:
https://x.com/XDevelopers/status/1228393702244134912
                                └── This is the Post ID
3

Send the like request

cURL
curl -X POST "https://api.x.com/2/users/123456789/likes" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"tweet_id": "1228393702244134912"}'
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)

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

print(f"Liked: {response.data.liked}")
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 });

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

console.log(`Liked: ${response.data?.liked}`);
4

Review the response

{
  "data": {
    "liked": true
  }
}

Unlike a Post

Remove a like from a Post:
cURL
curl -X DELETE "https://api.x.com/2/users/123456789/likes/1228393702244134912" \
  -H "Authorization: Bearer $USER_ACCESS_TOKEN"
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)

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

print(f"Liked: {response.data.liked}")
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 });

// Unlike a Post
const response = await client.posts.unlike("123456789", "1228393702244134912");

console.log(`Liked: ${response.data?.liked}`);
Response:
{
  "data": {
    "liked": false
  }
}

Next steps

Likes lookup

Get users who liked a Post

API Reference

Full endpoint documentation