Likes lookup
Getting started with the Likes lookup endpoint
This quick start guide will help you make your first request to the Likes lookup endpoint using Postman.
If you would like to see sample code in different languages, please visit our X API v2 sample code GitHub repository.
Prerequisites
For you to be able to complete this guide, you will have need to have a set of keys and tokens, which you can generate by following these steps:
-
Apply for a developer account and receive approval.
-
Create a Project and an associated developer App in the developer portal.
-
Navigate to your app’s “Keys and tokens” page, and save your API Keys, Access Tokens, and Bearer Token to your password manager.
Steps to build a Likes lookup request
Step one: Start with a tool or library
There are several different tools, code examples, and libraries that you can use to make a request to this endpoint, but we will use the Postman tool here to simplify the process.
To load the X API v2 Postman collection into your environment, please click on the following button:
Once you have the X API v2 collection loaded in Postman, navigate to the “Likes” folder and select “Liking users.”
Step two: Authenticate your request
To make a successful request to this endpoint, you will need to use either OAuth 1.0a User Context or OAuth 2.0 Bearer Token authentication. To do this, you must add the following keys and tokens to Postman by selecting the environment named “X API v2”, and adding the following variables to the Initial value and Current value fields:
- consumer_key with your API Key
- consumer_secret with your API Key Secret
- access_token with your Access Token
- token_secret with your Access Token Secret
Step three: Specify a Tweet
With this endpoint, you must specify the Tweet ID that you want to get liking users for. You can find the ID of a Tweet by navigating to that Tweet on Twitter and pulling the numerical code at the end of the URL. For example, the following URL’s Tweet ID is 1354143047324299264.
https://twitter.com/TwitterDev/status/1354143047324299264
In Postman, navigate to the “Params” tab and enter this username into the “Value” column of the tweet_id path variable (at the bottom of the section), making sure to not include any spaces before or after usernames.
Key | Value |
id | The Tweet ID you want to get the liking users of |
Step four: Identify and specify which fields you would like to retrieve
If you click the “Send” button after step three, you will receive the default user object fields in your response: id, name, and username.
If you would like to receive additional fields beyond id, name, and username, you will have to specify those fields in your request with the fields and/or expansions parameters.
For this exercise, we will request three additional sets of fields from different objects:
- The additional user.created_at field in the primary user objects.
- The associated pinned Tweets’ object’s default fields for the returned users: id and text.
- The additional tweet.created_at field in the associated Tweet objects.
In Postman, navigate to the “Params” tab and add the following key:value pair to the “Query Params” table:
Key | Value | Returned fields |
user.fields | created_at | user.created_at |
expansions | pinned_tweet_id | tweet.id, tweet.text |
tweet.fields | created_at | tweet.created_at |
You should now see the following URL next to the “Send” button:
https://api.x.com/2/tweets/1354143047324299264/liking_users?user.fields=created_at&expansions=pinned_tweet_id&tweet.fields=created_at
Step five: Make your request and review your response
Once you have everything set up, hit the “Send” button and you will receive a similar response to the following example response:
Step six: Get a user’s liked Tweets
You might also want to make a request to get a user’s liked Tweets as well. With the Likes lookup endpoint, you can get information about a user’s liked Tweets. To do this navigate to the “Likes” folder and select “Liked Tweets”.
With this endpoint, you must specify the User ID that you want to get liking users for. You can use the user lookup endpoint to get this information.
In Postman, navigate to the “Params” tab and enter this username into the “Value” column of the id path variable (at the bottom of the section), making sure to not include any spaces before or after usernames.
Key | Value |
id | The user ID you want to get the liked Tweets of |
max_results | 5 |
You can now see a similar URL with your ID instead of TwitterDev’s next to the “Send” button:
https://api.x.com/2/users/2244994945/liked_tweets?max_results=5
Once you have everything set up, hit the “Send” button and you will receive a similar response to the following example response: