Getting started with the manage follows endpoints

This quick start guide will help you make your first request to the manage follows endpoints using Postman.

If you would like to see sample code in different languages, please visit our Twitter 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:

  1. Apply for a developer account and receive approval.
  2. If you already have a developer account, activate the new developer portal.
  3. Create a Project and an associated developer App in the developer portal.
  4. 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 manage follows 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 are going to use the Postman tool here to simplify the process.

To load the Twitter API v2 Postman collection into your environment, please click on the following button:

Once you have the Twitter API v2 collection loaded in Postman, navigate to the “Follows” folder, and select “Follow a user ID”.

Step two: Authenticate your request

To make a successful request to this endpoint, you will need to use OAuth 1.0a User Context. To do this, you must add the following keys and tokens to Postman by selecting the environment named “Twitter 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 who is going to follow whom

Manage follows endpoints take two IDs: one for the source user (the user who wishes to follow or unfollow another user) and the target user (the user that will be followed or unfollowed). The source user’s ID must correspond to the user ID of the authenticating user. In this case, you can specify the ID belonging to your own user. You can find your ID in two ways:

  1. Using the user lookup by username endpoint, you can pass a username and receive the id field. 
  2. Looking at your Access Token, you will find that the numeric part is your user ID.
     

The target ID can be any valid user ID. For example the user ID for @TwitterDev is 2244994945.

In Postman, navigate to the "Params" tab, and enter your ID into the "Value" column of the id path variable. Navigate to the “Body” tab and and 2244994945 (the user ID for @TwitterDev) as the value for the target_user_id parameter. Making sure to not include any spaces before or after any ID.

Key Value
source_user_id (your user ID)
target_user_id 2244994945


If you click the "Send" button, you will receive a response object containing the status of the relationship:

  • If you receive a "following": true, then the source_user_id is successfully following the target_user_id.
  • If you receive a "pending": true, then the target_user_id is protected and must accept your follow request.


Step four: Make your request and review your response

Once you have everything set up, hit the "Send" button and you will receive the following response:

      {
    "data": {
        "following": true,
        "pending_follow": false
    }
}
    

 

Similarly, if you were trying to unfollow a user, you would use the "Unfollow a user ID" request within the same Postman collection. However, both the source_user_id and target_user_id parameters should be passed as path variables using the unfollow endpoint. 

Was this document helpful?
Thank you

Thank you for the feedback. We’re really glad we could help!

Thank you for the feedback. How could we improve this document?
Thank you for the feedback. Your comments will help us improve our documents in the future.