This page contains information on several tools and key concepts that you should be aware of as you integrate the users lookup endpoints into your system. We’ve broken the page into a couple of different sections:
- Helpful tools
- Key Concepts
- Developer portal, Projects, and Apps
- Rate limits
- Fields and expansions
- Edge cases
Before we dive into some key concepts that will help you integrate this endpoint, we recommend that you become familiar with:
Postman is a great tool that you can use to test out an endpoint. Each Postman request includes every path and body parameter to help you quickly understand what is available to you. To learn more about our Postman collections, please visit our "Using Postman" page.
Interested in getting set up with this endpoint with some code in your preferred coding language? We’ve got a handful of different code samples available that you can use as a starting point on our Github page.
Take advantage of one of our communities’ third-party libraries to help you get started. You can find a library that works with the v2 endpoints by looking for the proper version tag.
All Twitter API v2 endpoints require for you to authenticate your requests with a set of credentials, also known as keys and tokens. You can use either OAuth 1.0a User Context, OAuth 2.0 Authorization Code Flow or OAuth 2.0 Bearer Token to authenticate your requests to this endpoint.
For OAuth 2.0 the Authorization Code Flow with PKCE supports both confidential and public clients to exchange an authorization code for an access token.
OAuth 1.0a User Context, which means that you must use a set of API keys and user access tokens to make a successful request. The access tokens must be associated with the user that you are making the request on behalf of. If you would like to generate a set of access tokens for another user, they must authorize or authenticate your App using the 3-legged OAuth flow.
Please note that OAuth 1.0a can be difficult to use. If you are not familiar with this authentication method, we recommend that you use a library, use a tool like Postman, or to use OAuth 2.0 Bearer Token to properly authenticate your requests.
OAuth 2.0 Bearer Token just requires that you pass a Bearer Token with your request. You can either generate a Bearer Token from directly within a developer App, or generate one using the POST oauth2/token endpoint.’
If you are requesting the following fields, OAuth 1.0a User Context or OAuth 2.0 Authorization Code is required:
To retrieve a set of authentication credentials that will work with the Twitter API v2 endpoints, you must sign up for a developer account, set up a Project within that account, and created a developer App within that Project. You can then find your keys and tokens within your developer App.
Every day, many thousands of developers make requests to the Twitter API. To help manage the sheer volume of these requests, rate limits are placed on each endpoint that limits the number of requests that you can make on behalf of your app or on behalf of an authenticated user.
The user lookup endpoints are rate limited at both the app-level and the user-level. However, the authenticated user lookup endpoint is rate limited at the user-level
The app-level rate limit means that you, the developer, can only make a certain number of requests to this endpoint over a given period of time from any given App (assumed by the keys and tokens that you are using. The user-level rate limit means that the authenticated user that you are making the request on behalf of can only perform a certain number of times across any developer App.
The chart below shows the rate limits for each endpoint.
Rate limit / Level
900 requests per 15 minutes / App and User
900 requests per 15 minutes / App and User
|/2/users/by||GET||900 requests per 15 minutes / App and User|
|/2/users/by/username/:username||GET||900 requests per 15 minutes / App and User|
|/2/users/me||GET||75 requests per 15 minutes / User|
The Twitter API v2 allows users to select exactly which data they want to return from the API using a set of tools called fields and expansions. The expansion parameter allows you to expand objects referenced in the payload. For example, this endpoint allows you to use the pinned_tweet_id expansion.
The fields parameter allows you to select exactly which fields within the different data objects you would like to receive. These endpoints delivers user objects primarily. By default, the user object returns the id, name, and username fields. To receive additional fields such as user.created_at or user.location, you will have to specifically request those using a fields parameter. Some important fields that you may want to consider using in your integration are our Tweet poll data, metrics, annotations, and conversation ID fields.
- Tweet text is truncated for Retweets. The short term workaround is to expand the referenced Tweet and retrieve the full text from the expansion. This is a bug that we will fix in the future.