Search tweets
Introduction
Searching for Posts is an important feature used to surface X conversations about a specific topic or event. While this functionality is present in X, these endpoints provide greater flexibility and power when filtering for and ingesting Posts so you can find relevant data for your research more easily; build out near-real-time ‘listening’ applications; or generally explore, analyze, and/or act upon Posts related to a topic of interest.
We offer two endpoints that allow you to search for Posts: Recent search and full-archive search. Both of these REST endpoints share a common design and features, including their use of a single search query to filter for Posts around a specific topic. These search queries are created with a set of operators that match on Post and user attributes, such as message keywords, hashtags, and URLs. Operators can be combined into queries with boolean logic and parentheses to help refine the queries matching behavior.
Both the recent search and the full-archive search endpoints provide edited Post metadata. All objects for Posts created since September 29, 2022, include Post edit metadata, even if the Post was never edited. Each time a Post is edited, a new Post ID is created. A Post’s edit history is documented by an array of Post IDs, starting with the original ID.
These endpoints will always return the most recent edit, along with any edit history. Any Post collected after its 30-minute edit window will represent its final version. To learn more about Edit Post metadata, check out the Edit Posts fundamentals page.
Once you’ve set up your query and start receiving Posts, these endpoints support navigating the results both by time and Post ID ranges. This is designed to support two common use cases:
- Get historical: Requests are for a period of interest, with no focus on the real-time nature of the data. A single request is made, and all matching data is delivered using pagination as needed. This is the default mode for Search Posts.
- Polling or listening: Requests are made in a “any new Posts since my last request?” mode. Requests are made on a continual basis, and typically there is a use case focused on near real-time ‘listening’ for Posts of interest.
Many operators and query limits are exclusive to Enterprise access, meaning that you must use keys and tokens from an App within a Project with Enterprise access to utilize the additional functionality. You can learn more about this in the endpoint sections below.
Both the recent search and the full-archive search endpoints returned Posts contribute to the monthly Post cap.
Account setup
To access these endpoints, you will need:
- An approved developer account.
- To authenticate using the keys and tokens from a developer App that is located within a Project.
Learn more about getting access to the X API v2 endpoints in our getting started guide.
Recent search
The recent search endpoint allows you to programmatically access filtered public Posts posted over the last week, and is available to all developers who have a developer account and are using keys and tokens from an App within a Project.
You can authenticate your requests with OAuth 1.0a User Context, OAuth 2.0 App-Only, or OAuth 2.0 Authorization Code with PKCE. However, if you would like to receive private metrics, or a breakdown of organic and promoted metrics within your Post results, you will have to use OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE, and pass user Access Tokens that are associated with the user that published the given content.
This endpoint can deliver up to 100 Posts per request in reverse-chronological order, and pagination tokens are provided for paging through large sets of matching Posts.
When using a Project with regular access, you can use the basic set of operators and can make queries up to 512 characters long. When using a Project with Enterprise access, you have access to additional operators. Projects with Enterprise Access can make queries up to 4096 characters long.
Learn more about access levels.
Full-archive search
The v2 full-archive search endpoint is only available to Projects with Pro access and Enterprise access. The endpoint allows you to programmatically access public Posts from the complete archive dating back to the first Post in March 2006, based on your search query.
You can authenticate your requests to this endpoint using OAuth 2.0 App-Only, and the App Access Token must come from an App that is within a Project that has Pro or Enterprise access. Since you cannot make a request on behalf of other users (OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE) with this endpoint, you will not be able to pull private metrics.
This endpoint can deliver up to 500 Posts per request in reverse-chronological order, and pagination tokens are provided for paging through large sets of matching Posts.
Note: If requesting annotations through the tweet.fields parameter, the max_results parameter is currently limited to a max value of 100. This may change in the future, but please be mindful of this limitation.
Since this endpoint is only available to those that have been approved for Pro and Enterprise access, you have access to the full set of search operators and can make queries up to 1024 characters long.
Quick Start
Getting started with the recent search endpoint
This quick start guide will help you make your first request to the recent search endpoint with a set of specified fields using Postman.
If you would like to see sample code in different languages, please visit our X API v2 sample code GitHub repository.
Prerequisites
To complete this guide, you will need to have a set of keys and tokens to authenticate your request. You can generate these keys and tokens by following these steps:
- Sign up 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 to generate the required credentials. Make sure to save all credentials in a secure location.
Steps to build a recent search 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 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 Search Posts > Recent search request.
Step two: Authenticate your request
To properly make a request to the X API, you need to verify that you have permission. To do this with this endpoint, you must authenticate your request with either OAuth 2.0 App-Only, OAuth 2.0 Authorization Code with PKCE, or OAuth 1.0a User Context authentication methods.
For simplicity’s sake, we will utilize OAuth 2.0 App-Only with this request, but you will need to use one of the other authentication methods if you’d like to request private metrics or Posts.
To utilize OAuth 2.0 App-Only, you must add your keys and tokens, specifically the App Access Token (also known as the App-only Bearer Token) to Postman. You can do this by selecting the environment named “X API v2” in the top-right corner of Postman and adding your keys and tokens to the “initial value” and “current value” fields (by clicking the eye icon next to the environment dropdown).
These variables will automatically be pulled into the request’s authorization tab if you’ve done this correctly.
Step three: Create a search query
Each recent search query requires a single search query. For this example, we are going to use a query that matches on Posts posted by the @XDevelopers account. For this query we use the from operator and set it to XDevelopers (case insensitive):
from:XDevelopers
In Postman, navigate to the “Params” tab and enter this ID, or a string of Post IDs separated by a comma, into the “Value” column of the ids
parameter.
Key | Value | Description |
query | from:XDevelopers | Search query to submit to the recent search endpoint |
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 Post object fields in your response: id , text, and edit_history_tweet_ids
. If you would like to receive additional fields beyond id , text, and edit_history_tweet_ids
, you will have to specify those fields in your request with the field and/or expansion parameters.
For this exercise, we will request a four different sets of fields from different objects:
- The default Post object fields.
- The additional tweet.created_at field in the primary user objects.
- The associated authors’ user object’s default fields for the returned Posts.
- The additional user.description field in the associated user objects.
In Postman, navigate to the “Params” tab and add the following key:value pair to the “Query Params” table:
Key | Value | Returned fields |
tweet.fields | created_at | tweets.created_at |
expansions | author_id | includes.users.id , includes.users.name , includes.users.username |
user.fields | description | includes.users.description |
You should now see the following URL next to the “Send” button:
https://api.x.com/2/tweets/search/recent?query=from:XDevelopers&tweet.fields=created_at&expansions=author_id&user.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 the following response:
Getting started with the full-archive search endpoint
This quick start guide will help you make your first request to the full-archive search endpoint with a set of specified fields using Postman.
If you would like to see sample code in different languages, please visit our X API v2 sample code GitHub repository.
Prerequisites
The full-archive search endpoint is currently available as part of the Pro and Enterprise access only. In order to use this endpoint, you must upgrade to Pro access or apply for Enterprise access level.
In addition to being approved for access, you will need to have a set of keys and tokens to authenticate your request. You can generate these keys and tokens by following these steps:
-
Navigate to your Project with Enterprise or Pro access in the developer portal and make sure you have an associated developer App within that Project.
-
Navigate to your App’s “Keys and tokens” page to generate the required credentials. Make sure to save all credentials in a secure location.
Steps to build a full-archive search 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 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 Search Posts > Full-archive search request.
Step two: Authenticate your request
To properly make a request to the X API, you need to verify that you have permission. To do so with this endpoint, you must authenticate your request with the OAuth 2.0 App-Only authentication methods.
You must add your keys and tokens, specifically the App Access Token (also known as the App-only Bearer Token) to Postman. You can do this by selecting the environment named “X API v2” in the top-right corner of Postman and adding your keys and tokens to the “initial value” and “current value” fields (by clicking the eye icon next to the environment dropdown).
This variable will automatically be pulled into the request’s authorization tab if you’ve done this correctly.
Step three: Create a search query
Each full-archive search query requires a single search query. For this example, we are going to use a query that matches on Posts posted by the @XDevelopers account. For this query we use the from operator and set it to XDevelopers (case insensitive):
from:XDevelopers
In Postman, navigate to the “Params” tab and enter this ID, or a string of Post IDs separated by a comma, into the “Value” column of the ids
parameter.
Key | Value | Description |
---|---|---|
query | from:XDevelopers | Search query to submit to the full-archive search endpoint |
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 Post object fields in your response: id
,text
, and edit_history_tweet_ids
. Note that if you receive Posts from before editing was supported, the edit_history_tweet_ids
field will not be provided. No history backfill was performed for this field.
If you would like to receive additional fields beyond these default fields, you will have to specify those fields in your request with the field and/or expansion parameters.
For this exercise, we will request a four different sets of fields from different objects:
- The default Post object fields
- The additional tweet.created_at field in the primary user objects
- The associated authors’ user object’s default fields for the returned Posts
- The additional user.description field in the associated user objects
In Postman, navigate to the “Params” tab and add the following key:value pair to the “Query Params” table:
Key | Value | Returned fields |
---|---|---|
tweet.fields | created_at | tweets.created_at |
expansions | author_id | includes.users.id, includes.users.name, includes.users.username |
user.fields | description | includes.users.description |
You should now see the following URL next to the “Send” button:
https://api.x.com/2/tweets/search/all?query=from:XDevelopers&tweet.fields=created_at&expansions=author_id&user.fields=created_at
Please note
By default, only 10 most recent Posts will be returned. If you want more than 10 Posts per request, you can use the max_results parameter and set it to a maximum of 500 Posts per request. Similarly, by default Posts from the last 30 days will be returned. If you want to get Posts that are older than 30 days, you can use the start_time and end_time parameters in your API call.
Step five: Make your request and review your response
Once you have everything set up, hit the “Send” button and you will receive a response similar to the following:
In this example, we used a very simple query. If you would like to see more detailed guides, please visit the resources listed below.
How to integrate with the Search Posts endpoints
This page contains information on several tools and key concepts that you should be aware of as you integrate the recent search or full archive search endpoints into your system. We’ve split the page into the following sections:
- Helpful tools
- Key concepts
Helpful tools
Before we start to explore some key concepts, we recommend that you use one of the following tools or code samples to start testing the functionality of these endpoints.
Code samples
Interested in getting set up with these endpoints 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, including a Python client and a Ruby client.
Libraries
Take advantage of one of our many community third-party libraries to help you get started. You can find a library that works with the v2 endpoints by looking for the appropriate version tag.
Postman
Postman is a great tool that you can use to test out these endpoints. Each Postman request includes all of the given endpoint’s parameters to help you quickly understand what is available to you. To learn more about our Postman collections, please visit our Using Postman page.
Key concepts
Authentication
All X API v2 endpoints require 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 App-Only, or OAuth 2.0 Authorization Code with PKCE to authenticate your requests to the recent search endpoint. You must use OAuth 2.0 App-Only when using the full archive search endpoint.
OAuth 2.0 App-Only just requires that you pass an OAuth 2.0 App Access Token with your request. You can either generate an App Access Token from directly within a developer App, or generate one using the POST oauth2/token endpoint.
OAuth 1.0a User Context requires you to utilize your API Keys, user Access Tokens, and a handful of other parameters to create an authorization header, which you will then pass with your 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 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 use OAuth 2.0 to authenticate your requests. If you would like to request a Post or private metrics from these endpoints, you will need to use a either OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE, which will ensure that you have the proper permissions from the user that owns that content.
OAuth 2.0 Authorization Code with PKCE allows for greater control over an application’s scope, and authorization flows across multiple devices. OAuth 2.0 allows you to pick specific fine-grained scopes which give you specific permissions on behalf of a user.
To enable OAuth 2.0 in your App, you must enable it in your’s App’s authentication settings found in the App settings section of the developer portal.
Please note
If you are requesting the following fields, OAuth 1.0a User Context or OAuth 2.0 Authorization Code is required:
- tweet.fields.non_public_metrics
- tweet.fields.promoted_metrics
- tweet.fields.organic_metrics
- media.fields.non_public_metrics
- media.fields.promoted_metrics
- media.fields.organic_metrics
Developer portal, Projects, and developer Apps
To work with any X API v2 endpoints, you must have signed up for a developer account, set up a Project within that account, and created a developer App within that Project. Your keys and tokens within that developer App will work for these search endpoints.
You can use keys and tokens from a Project with any access level to make requests to the recent search endpoint. However, you will need to use Project with the Pro or Enterprise access level to make requests to the full archive search endpoint. If you have Enterprise access, you will have access to additional functionality, including the availability of additional operators and longer query lengths.
Rate limits
Every day, many thousands of developers make requests to the X API. To help manage the volume, rate limits are placed on each endpoint that limits the number of requests that every developer can make on behalf of an app or on behalf of an authenticated user.
There are different rate limits applied for these endpoints depending on which authentication method is being used. The app-level rate limits apply to an App making requests using OAuth 2.0 App-Only, whereas the user-level rate limit applies to requests being made on behalf of the specific authorizing user using OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE. These two rate limits are based on the frequency of requests within a 15-minute window.
For example, an app using OAuth 2.0 App-Only auth to make requests to the recent search endpoint can make 450 requests (including pagination requests) within a 15-minute timeframe. That same app, within the same 15-minute timeframe and with two different authenticated users (using OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE) can make up to 180 requests (including pagination requests) to the recent search endpoint for each authenticated user.
Fields and expansions
The X API v2 allows you to select exactly which data you want returned from the API using fields and expansions. The expansion parameter allows you to expand objects referenced in the payload. For example, this endpoint allows you to request poll, place, media, and other objects using the expansions parameter.
The fields parameters allows you to select exactly which fields within the different data objects you would like to receive. By default, the primary Post object returned by these endpoints include the id and text fields (in addition to edit_history_tweet_ids for Posts created after that feature was launched). To receive additional fields such as author_id or public_metrics, you will have to specifically request those using the fields parameters. Some important fields that you may want to consider using in your integration are our poll data, metrics, Post annotations, and conversation ID fields.
We’ve added a guide on how to use fields and expansions together to our X API v2 data dictionary.
Metrics
The X API v2 endpoints allow you to request metrics directly from the returned objects, assuming you pass the proper fields with your request.
There are some limitations with Post metrics that you should be aware of, specifically related to user privacy and the following response fields:
- tweet.fields.non_public_metrics
- tweet.fields.promoted_metrics
- tweet.fields.organic_metrics
- media.fields.non_public_metrics
- media.fields.promoted_metrics
- media.fields.organic_metrics
The noted fields include private metrics data, meaning you must be authorized by the Post’s publisher to retrieve this data on their behalf when using the recent search endpoint, meaning you must use OAuth 1.0a User Context. Since you can only use this authentication method using recent search, you will not be able to retrieve these metrics via the full archive search endpoint.
For example, in order to receive non_public_metrics
for user ID 1234’s Posts, you will need to include access tokens associated with that user in your request. You can have users authorize your app and receive a set of access tokens associated with them by using the 3-legged OAuth flow.
All non_public_metrics
, organic_metrics
, and promoted_metrics are only available for Posts created in the last 30 days. This means that when you are requesting the noted fields, the results will automatically adjust to only include Posts from the last 30 days.
If these noted fields are requested, only Posts that are authored by the authenticated user will be returned, all other Posts will receive an error message.
Building search queries
The central feature of these endpoints is their use of a single search query to filter the Posts that deliver to you. These queries are made up of operators that match on Post and user attributes, such as message keywords, hashtags, and URLs. Operators can be combined into queries with boolean logic and parentheses to help refine the query’s matching behavior.
You can use our guide on how to build a query to learn more.
We have also written a more in-depth tutorial on how to [build high-quality filters for getting X data]https://developer.x.com/en/docs/tutorials/building-high-quality-filters.
Pagination
These endpoints utilize pagination so that responses are returned quickly. In cases where there are more results than what can be sent in a single response (up to 100 Posts for recent search and 500 for full-archive search) you will need to paginate. Use the max_results parameter to identify how many results will return per page, and the pagination_token parameter to return the next page of results. You can learn more by reviewing our pagination guide.
Post caps
The Search Posts endpoints are limited in the number of Posts that they can return in a given month, regardless of pagination.
Regardless of which search endpoint you use, the Posts returned will count towards the Project-level Post caps. Usage is shown in the developer portal, and the ‘month’ starts on your subscription renewal day shown on the developer portal dashboard.
Post edits
Posts that are eligible for edits can be edited up to five times in the 30 minutes after the original Post was published. The search endpoints will always provide the latest version of the Post. If you only request Posts that were published 30 or more minutes ago, you will always receive the final version of the Post. However, if you have a near-real-time use case, and are querying Posts published within the last thirty minutes, those Posts could have been edited after you received them. These Posts can be rehydrated with search, or the Post Lookup endpoint to confirm their final state. To learn more about how Post edits work, see the Post edits fundamentals page.
Building queries for Search Posts
The search endpoints accept a single query with a GET request and return a set of historical Posts that match the query. Queries are made up of operators that are used to match on a variety of Post attributes.
To learn more about how to create high-quality queries, visit the following tutorial: [Building high-quality filters for getting X data]https://developer.x.com/en/docs/tutorials/building-high-quality-filters
Table of contents
- Building a query
- Query limitations
- Operator availability
- Operator types: standalone and conjunction-required
- Boolean operators and grouping
- Order of operations
- Punctuation, diacritics, and case sensitivity
- Specificity and efficiency
- Quote Tweet matching behavior
- Iteratively building a query
- Adding a query to your request
- Query examples
- List of operators
Building a query
Query limitations
Your queries will be limited depending on which access level you are using.
If you have Basic or Pro access, your query can be 512 characters long for recent search endpoint.
If you have Pro access, your query can be 1,024 characters long for full archive search endpoint.
Operator availability
While most operators are available to any developer, there are several that are reserved for certain access levels. We list which access level each operator is available to in the list of operators table using the following labels:
- Core operators: Available when using any Project.
- Advanced operators: Available when using a Project with certain access level
Operator types: standalone and conjunction-required
Standalone operators can be used alone or together with any other operators (including those that require conjunction).
For example, the following query will work because it uses the #hashtag operator, which is standalone:
#xapiv2
Conjunction-required operators cannot be used by themselves in a query; they can only be used when at least one standalone operator is included in the query. This is because using these operators alone would be far too general, and would match on an extremely high volume of Posts.
For example, the following queries are not supported since they contain only conjunction-required operators:
has:media has:links OR is:retweet
If we add in a standalone operator, such as the phrase “X data”, the query would then work properly.
“X data” has:mentions (has:media OR has:links)
Boolean operators and grouping
If you would like to string together multiple operators in a single query, you have the following tools at your disposal:
AND logic | Successive operators with a space between them will result in boolean “AND” logic, meaning that Posts will match only if both conditions are met. For example, snow day #NoSchool will match Posts containing the terms snow and day and the hashtag #NoSchool. |
OR logic | Successive operators with OR between them will result in OR logic, meaning that Posts will match if either condition is met. For example, specifying grumpy OR cat OR #meme will match any Posts containing at least the terms grumpy or cat, or the hashtag #meme. |
NOT logic, negation | Prepend a dash (-) to a keyword (or any operator) to negate it (NOT). For example, cat #meme -grumpy will match Posts containing the hashtag #meme and the term cat, but only if they do not contain the term grumpy. One common query clause is -is:retweet, which will not match on Retweets, thus matching only on original Posts, Quote Tweets, and replies. All operators can be negated, but negated operators cannot be used alone. |
Grouping | You can use parentheses to group operators together. For example, (grumpy cat) OR (#meme has:images) will return either Posts containing the terms grumpy and cat, or Posts with images containing the hashtag #meme. Note that ANDs are applied first, then ORs are applied. |
A note on negations
The operators -is:nullcast must always be negated.
Negated operators cannot be used alone.
Do not negate a set of operators grouped together in a set of parentheses. Instead, negate each individual operator. For example, instead of using skiing -(snow OR day OR noschool), we suggest that you use skiing -snow -day -noschool.
Order of operations
When combining AND and OR functionality, the following order of operations will dictate how your query is evaluated.
- Operators connected by AND logic are combined first
- Then, operators connected with OR logic are applied
For example:
- apple OR iphone ipad would be evaluated as apple OR (iphone ipad)
- ipad iphone OR android would be evaluated as (iphone ipad) OR android
To eliminate uncertainty and ensure that your query is evaluated as intended, group terms together with parentheses where appropriate.
For example:
- (apple OR iphone) ipad
- iphone (ipad OR android)
Punctuation, diacritics, and case sensitivity
If you specify a keyword or hashtag query with character accents or diacritics, it will match Post text that contains both the term with the accents and diacritics, as well as those terms with normal characters. For example, queries with a keyword Diacrítica or hashtag #cumpleaños will match Diacrítica or #cumpleaños, as well as with Diacritica or #cumpleanos without the tilde í or eñe.
Characters with accents or diacritics are treated the same as normal characters and are not treated as word boundaries. For example, a query with the keyword cumpleaños would only match activities containing the word cumpleaños and would not match activities containing cumplea, cumplean, or os.
All operators are evaluated in a case-insensitive manner. For example, the query cat will match Posts with all of the following: cat, CAT, Cat.
The filtered stream matching behavior acts differently from Search Posts. When building a filtered stream rule, know that keywords and hashtags that include accents and diacritics will only match on terms that also include the accent and diacritic, and will not match on terms that use normal characters instead.
For example, filtered stream rules that include a keyword Diacrítica or hashtag #cumpleaños will only match the terms Diacrítica and #cumpleaños, and will not match on Diacritica or #cumpleanos without the tilde í or eñe
Specificity and efficiency
When you start to build your query, it is important to keep a few things in mind.
- Using broad, standalone operators for your query such as a single keyword or #hashtag is generally not recommended since it will likely match on a massive volume of Posts. Creating a more robust query will result in a more specific set of matching Posts, and will hopefully reduce the amount of noise in the payload that you will need to sift through to find valuable insights.
- For example, if your query was just the keyword happy you will likely get anywhere from 200,000 - 300,000 Posts per day.
- Adding more conditional operators narrows your search results, for example (happy OR happiness) place_country:GB -birthday -is:retweet
- Writing efficient queries is also beneficial for staying within the characters query length restriction. The character count includes the entire query string including spaces and operators.
- For example, the following query is 59 characters long: (happy OR happiness) place_country:GB -birthday -is:retweet
Quote Tweet matching behavior
When using the Search Posts endpoints, operators will not match on the content from the original Post that was quoted, but will match on the content included in the Quote Tweet.
However, please note that filtered stream will match on both the content from the original P that was quoted and the Quote Tweet’s content.
Iteratively building a query
Test your query early and often
Getting a query to return the “right” results the first time is rare. There is so much on X that may or may not be obvious at first and the query syntax described above may be hard to match to your desired search. As you build a query, it is important for you to periodically test it out.
For this section, we are going to start with the following query and adjust it based on the results that we receive during our test:
happy OR happiness
Use results to narrow the query
As you test the query, you should scan the returned Posts to see if they include the data that you are expecting and hoping to receive. Starting with a broad query and a superset of Post matches allows you to review the result and narrow the query to filter out undesired results.
When we tested the example query, we noticed that we were getting Po in a variety of different languages. In this situation, we want to only receive Posts that are in english, so we’re going to add the lang: operator:
(happy OR happiness) lang:en
The test delivered a number of Posts wishing people a happy birthday, so we are going to add -birthday as a negated keyword operator. We also want to only receive original Posts, so we’ve added the negated -is:retweet operator:
(happy OR happiness) lang:en -birthday -is:retweet
Adjust for inclusion where needed
If you notice that you are not receiving data that you expect and know that there are existing Posts that should return, you may need to broaden your query by removing operators that may be filtering out the desired data.
For our example, we noticed that there were other Posts in our personal timeline that expressed the emotion that we are looking for and weren’t included in the test results. To ensure we have greater coverage, we are going to add the keywords, excited and elated.
(happy OR happiness OR excited OR elated) lang:en -birthday -is:retweet
Adjust for popular trends/bursts over the time period
Trends come and go on X quickly. Maintaining your query should be an active process. If you plan to use a query for a while, we suggest that you periodically check in on the data that you are receiving to see if you need to make any adjustments.
In our example, we notice that we started to receive some Posts that are wishing people a “happy holidays”. Since we don’t want these Posts included in our results, we are going to add a negated -holidays keyword.
(happy OR happiness OR excited OR elated) lang:en -birthday -is:retweet -holidays
Adding a query to your request
To add your query to your request, you must use the query parameter. As with any query parameters, you must make sure to HTTP encode the query that you developed.
Here is an example of what this might look like using a cURL command, with an additional tweet.fields and max_results parameter included. If you would like to use this command, please make sure to replace $BEARER_TOKEN with your own Bearer Token:
curl https://api.x.com/2/tweets/search/recent?query=cat%20has%3Amedia%20-grumpy&tweet.fields=created_at&max_results=100 -H "Authorization: Bearer $BEARER_TOKEN"
Query examples
Tracking a natural disaster
The following query matched on original Posts coming from weather agencies and gauges that discuss Hurricane Harvey, which hit Houston in 2017.
Here is what the query would look like without the HTTP encoding:
has:geo (from:NWSNHC OR from:NHC_Atlantic OR from:NWSHouston OR from:NWSSanAntonio OR from:USGS_TexasRain OR from:USGS_TexasFlood OR from:JeffLindner1) -is:retweet
And here is what the query would look like with the HTTP encoding, the query parameter, and the recent search URI:
Reviewing the sentiment of a conversation
The next rule could be used to better understand the sentiment of the conversation developing around the hashtag, #nowplaying, but scoped to just Posts published within North America.
Here is what the two different queries, one for positive and one for negative, would look like without the HTTP encoding:
#nowplaying (happy OR exciting OR excited OR favorite OR fav OR amazing OR lovely OR incredible) (place_country:US OR place_country:MX OR place_country:CA) -horrible -worst -sucks -bad -disappointing
#nowplaying (horrible OR worst OR sucks OR bad OR disappointing) (place_country:US OR place_country:MX OR place_country:CA) -happy -exciting -excited -favorite -fav -amazing -lovely -incredible
And here is what the query would look like with the HTTP encoding, the query parameter, and the recent search URI:
Find Posts that relate to a specific Post annotation
This rule was built to search for original Posts that included an image of a pet that is not a cat, where the language identified in the Post is Japanese. To do this, we used the context: operator to take advantage of the Post annotation functionality. We first used the Post lookup endpoint and the tweet.fields=context_annotations fields parameter to identify which domain.entity IDs we need to use in our query:
- Posts that relate to cats return domain 66 (Interests and Hobbies category) with entity 852262932607926273 (Cats).
- Posts that relate to pets return domain 65 (Interests and Hobbies Vertical) with entity 852262932607926273 (Pets).
Here is what the query would look like without the HTTP encoding:
context:65.852262932607926273 -context:66.852262932607926273 -is:retweet has:images lang:ja
And here is what the query would look like with the HTTP encoding, the query parameter, and the recent search URI:
Try out the query builder tool for additional support.
Operators
Operator Guide
Operator | Type | Availability | Description |
---|---|---|---|
keyword | Standalone | Essential | Matches a keyword within the body of a Post. This is a tokenized match, meaning that your keyword string will be matched against the tokenized text of the Post body. Tokenization splits words based on punctuation, symbols, and Unicode basic plane separator characters. For example, a Post with the text “I like coca-cola” would be split into the following tokens: I, like, coca, cola. These tokens would then be compared to the keyword string used in your query. To match strings containing punctuation (for example coca-cola), symbol, or separator characters, you must wrap your keyword in double-quotes. Example: pepsi OR cola OR "coca cola" |
emoji | Standalone | Essential | Matches an emoji within the body of a Post. Similar to a keyword, emojis are a tokenized match, meaning that your emoji will be matched against the tokenized text of the Post body. Note that if an emoji has a variant, you must wrap it in double quotes to add to a query. Example: (😃 OR 😡) 😬 |
”exact phrase match” | Standalone | Essential | Matches the exact phrase within the body of a Post. Example: ("X API" OR #v2) -"recent search" |
# | Standalone | Essential | Matches any Post containing a recognized hashtag, if the hashtag is a recognized entity in a Post. This operator performs an exact match, NOT a tokenized match, meaning the rule #thanku will match posts with the exact hashtag #thanku, but not those with the hashtag #thankunext. Example: #thankunext #fanart OR @arianagrande |
@ | Standalone | Essential | Matches any Post that mentions the given username, if the username is a recognized entity (including the @ character). Example: (@XDevelopers OR @API) -@X |
$ | Standalone | Elevated | Matches any Post that contains the specified ‘cashtag’ (where the leading character of the token is the ‘twtr OR @XDevelopers -$fb` |
from: | Standalone | Essential | Matches any Post from a specific user. The value can be either the username (excluding the @ character) or the user’s numeric user ID. You can only pass a single username/ID per from: operator. Example: from:XDevelopers OR from:API -from:X |
to: | Standalone | Essential | Matches any Post that is in reply to a particular user. The value can be either the username (excluding the @ character) or the user’s numeric user ID. You can only pass a single username/ID per to: operator. Example: to:XDevelopers OR to:API -to:X |
url: | Standalone | Essential | Performs a tokenized match on any validly-formatted URL of a Post. This operator can match on the contents of both the url or expanded_url fields. Example: from:XDevelopers url:"https://developer.twitter.com" |
retweets_of: | Standalone | Essential | Matches Posts that are Retweets of the specified user. You can only pass a single username/ID per retweets_of: operator. Example: retweets_of:twitterdev OR retweets_of:twitterapi |
in_reply_to_tweet_id: | Standalone | Essential | Available alias: in_reply_to_status_id Matches on replies to the specified Post. Example: in_reply_to_tweet_id:1539382664746020864 |
retweets_of_tweet_id: | Standalone | Essential | Available alias: retweets_of_status_id Matches on explicit (or native) Retweets of the specified Post. Example: retweets_of_tweet_id:1539382664746020864 |
quotes_of_tweet_id: | Standalone | Essential | Available alias: quotes_of_status_id Matches on Quote Tweets of the specified Post. Example: quotes_of_tweet_id:1539382664746020864 |
context: | Standalone | Essential | Matches Posts with a specific domain id/entity id pair. To learn more, visit the annotations page. Example: (context:47.1139229372198469633 OR context:11.1088514520308342784) |
entity: | Standalone | Essential | Matches Posts with a specific entity string value. Visit the annotations page for details. Example: entity:"Michael Jordan" OR entity:"Barcelona" |
conversation_id: | Standalone | Essential | Matches Posts that share a common conversation ID. Example: conversation_id:1334987486343299072 |
list: | Standalone | Elevated | Matches Posts posted by users who are members of a specified list. Example: list:123 |
place: | Standalone | Elevated | Matches Posts tagged with the specified location or X place ID. Example: place:"new york city" OR place:seattle |
place_country: | Standalone | Elevated | Matches Posts where the country code associated with a tagged place/location matches the given ISO alpha-2 character code. Example: place_country:US |
point_radius: | Standalone | Elevated | Matches against the place.geo.coordinates object of the Post when present, and in X, against a place geo polygon. Example: point_radius:[2.355128 48.861118 16km] |
bounding_box: | Standalone | Elevated | Available alias: geo_bounding_box Matches against the place.geo.coordinates object of the Post when present. Example: bounding_box:[-105.301758 39.964069 -105.178505 40.09455] |
is:retweet | Conjunction required | Essential | Matches on Retweets that match the rest of the specified rule. Example: data @XDeveloeprs -is:retweet |
is:reply | Conjunction required | Essential | Matches explicit replies that match a rule. Example: from:XDeveloeprs is:reply |
is:quote | Conjunction required | Essential | Returns all Quote Tweets, also known as Posts with comments. Example: "sentiment analysis" is:quote |
is:verified | Conjunction required | Essential | Deliver only Posts whose authors are verified by X. Example: #nowplaying is:verified |
-is:nullcast | Conjunction required | Elevated | Removes Posts created for promotion only on ads.twitter.com. Example: "mobile games" -is:nullcast |
has:hashtags | Conjunction required | Essential | Matches Posts that contain at least one hashtag. Example: from:XDeveloeprs -has:hashtags |
has:cashtags | Conjunction required | Elevated | Matches Posts that contain a cashtag symbol (with a leading ‘$’ character). Example: #stonks has:cashtags |
has:links | Conjunction required | Essential | Matches Posts that contain links and media in the Post body. Example: from:XDeveloeprs announcement has:links |
has:mentions | Conjunction required | Essential | Matches Posts that mention another X user. Example: #nowplaying has:mentions |
has:media | Conjunction required | Essential | Available alias: has:media_link Matches Posts that contain a media object. Example: (kittens OR puppies) has:media |
has:images | Conjunction required | Essential | Matches Posts that contain a recognized URL to an image. Example: #meme has:images |
has:video_link | Conjunction required | Essential | Available alias: has:videos Matches Posts that contain native X videos. Example: #icebucketchallenge has:video_link |
has:geo | Conjunction required | Elevated | Matches Posts that contain location information in geo.place.geo.coordinates object. Example: @API has:geo |
sample: | Standalone | Elevated | Matches a percentage sample from the universe of all published Posts that match your search rules. Example: sample:10 |
The list below represents the currently supported languages and their corresponding BCP 47 language identifier:
Amharic: am | German: de | Malayalam: ml | Slovak: sk |
Arabic: ar | Greek: el | Maldivian: dv | Slovenian: sl |
Armenian: hy | Gujarati: gu | Marathi: mr | Sorani Kurdish: ckb |
Basque: eu | Haitian Creole: ht | Nepali: ne | Spanish: es |
Bengali: bn | Hebrew: iw | Norwegian: no | Swedish: sv |
Bosnian: bs | Hindi: hi | Oriya: or | Tagalog: tl |
Bulgarian: bg | Latinized Hindi: hi-Latn | Panjabi: pa | Tamil: ta |
Burmese: my | Hungarian: hu | Pashto: ps | Telugu: te |
Croatian: hr | Icelandic: is | Persian: fa | Thai: th |
Catalan: ca | Indonesian: in | Polish: pl | Tibetan: bo |
Czech: cs | Italian: it | Portuguese: pt | Traditional Chinese: zh-TW |
Danish: da | Japanese: ja | Romanian: ro | Turkish: tr |
Dutch: nl | Kannada: kn | Russian: ru | Ukrainian: uk |
English: en | Khmer: km | Serbian: sr | Urdu: ur |
Estonian: et | Korean: ko | Simplified Chinese: zh-CN | Uyghur: ug |
Finnish: fi | Lao: lo | Sindhi: sd | Vietnamese: vi |
French: fr | Latvian: lv | Sinhala: si | Welsh: cy |
Georgian: ka | Lithuanian: lt |
Recent search pagination
Introduction
Search queries typically match on more Posts than can be returned in a single API response. When that happens, the data is returned in a series of ‘pages’. Pagination refers to methods for requesting all of the pages in order to retrieve the entire data set.
Here are fundamental recent search pagination details:
-
The recent search endpoints will respond to a query with at least one page, and provide a next_token in its JSON response if additional pages are available. To receive matching Posts, this process can be repeated until no token is included in the response.
-
The next_token does not expire. Multiple requests using the same next_token value will receive the same results, regardless of when the request is made.
-
Posts are delivered in reverse-chronological order, in the UTC timezone. This is true within individual pages, as well as across multiple pages:
- The first Post in the first response will be the most recent one matching your query.
- The last Post in the last response will be the oldest one matching your query.
-
The max_results request parameter enables you to configure the number of Posts returned per response. This defaults to 10 Posts and has a maximum of 100.
-
Every pagination implementation will involve parsing next_tokens from the response payload, and including them in the ‘next page’ search request. See below for more details on how to construct these ‘next page’ requests.
The recent search endpoint was designed to support two fundamental use patterns:
-
Get historical - Requesting matching Posts from a time period of interest. These are typically one-time requests in support of historical research. Search requests can be based on start_time and end_time request parameters. recent search endpoint respond with Posts delivered in reverse-chronological order, starting with the most recent matching Post.
-
Polling - Requesting matching Posts that have been posted since the last Post received. These use cases often have a near-real-time focus and are characterized by frequent requests, “listening” for new Posts of interest. The recent search endpoint provide the since_id request parameter in support of the ‘polling’ pattern. To help with navigating by Post IDs, the until_id request parameter is also available.
Next, we’ll discuss the historical mode. This is the default mode of the recent search endpoint and illustrates the fundamentals of pagination. Then we’ll discuss examples of polling use cases. When polling triggers pagination, there is an additional step to manage search requests.
Retrieving historical data
This section outlines how you can retrieve Posts from a period of interest (currently limited to the last seven days) using the start_time and end_time request parameters. Historical requests are typically one-time requests in support of research and analysis.
Making requests for a period of data is the default mode of the recent search endpoint. If a search request does not specify a start_time, end_time, or since_id request parameter, the end_time will default to “now” (actually 30 seconds before the time of query) and the start_time will default to seven days ago.
The endpoint will respond with the first ‘page’ of Posts in reverse-chronological order, starting with the most recent Post. The response JSON payload will also include a next_token if there are additional pages of data. To collect the entire set of matching Posts, regardless of the number of pages, requests are made until no next_token is provided.
For example, here is an initial request for Posts with the keyword snow from the last week:
https://api.x.com/2/tweets/search/recent?query=snow
The response includes the most recent 10 Posts, along with these “meta” attributes in the JSON response:
To retrieve the next 10 Posts, this next_token is added to the original request. The request would be:
The process of looking for a next_token and including it in a subsequent request can be repeated until all (or some number of) Posts are collected, or until a specified number of requests have been made. If data fidelity (collecting all matches of your query) is key to your use case, a simple “repeat until request.next_token is null” design will suffice.
Polling and listening use cases
This section outlines how you can retrieve recent Posts by polling the recent search endpoint with the since_id request parameter.
With polling use cases, “any new Posts of interest?” queries are made on an on-going, frequent basis. Unlike historical use cases, that base requests on time, polling use cases typically base requests on Post IDs.
Central to the polling use pattern is that every new Post has a unique ID that is ‘emitted’ from the X platform generally in ascending order. If one Post has an ID smaller than another, it means it was posted earlier.
The recent search endpoint support navigating the Post archive by Post ID. Responses from the endpoint include oldest_id and newest_id Post IDs. In the polling mode, requests are made with the since_id set to the largest/newest ID received so far.
For example, say a query for new Posts about snow is made every five minutes, and the last Post we received had a Post ID of 10000. When it is time to poll, the request looks like:
https://api.x.com/2/tweets/search/recent?query=snow&since_id=10000
Next, let’s say seven Posts were posted since our last request. Since all of these fit on a single data ‘page’, there is no next_token. The response provides the Post ID of the most recent (newest) Post:
To make the next polling query, this newest_id value is used to set the next since_id parameter:
https://api.x.com/2/tweets/search/recent?query=snow&since_id=12000
When there is more data available, and next tokens are provided, only th newest_id value from the first page of results is needed. Each page of data will include newest_id and oldest_id values, but the value provided in the first page is the only one needed for the next, regularly scheduled, polling request. So, If you are implementing a polling design, or searching for Posts by ID range, pagination logic is slightly more complicated.
Now say that there are now 18 more matching Posts. The endpoint would respond with this initial response with a full data page and a next_token for requesting the next page of data from this five minute period. It would also include the newest Post ID need for the next polling interval in five minutes.
To collect all the matching data for this five minute period, pass the next_token in your next request, along with the same since_id value as the previous request.
This second response provides the remaining eight Posts, and no next_token. Note that we do not update our newest_id value (12300), and instead base our next since_id request on the first response’s newest_id value:
https://api.x.com/2/tweets/search/recent?query=snow&since_id=13800
Comparing X API’s Search Posts endpoints
The v2 Search Tweets endpoint will eventually replace the standard v1.1 search/posts endpoint and enterprise Search API. If you have code, apps, or tools that use an older version of a X search endpoint and are considering migrating to the newer X API v2 endpoints, then this guide is for you.
This page contains three comparison tables:
Recent search comparison
The following table compares the various types of recent search endpoints:
Description | Standard v1.1 | X API v2 |
---|---|---|
Host domain | https://api.x.com | https://api.x.com |
Endpoint path | /1.1/search/tweets.json | /2/tweets/search/recent |
Authentication | OAuth 1.0a User Context OAuth 2.0 App-Only | OAuth 1.0a User Context OAuth 2.0 Authorization Code with PKCE OAuth 2.0 App-Only |
Timestamp format | YYYYMMDD | YYYY-MM-DDTHH:mm:ssZ ISO 8601 / RFC 3339 |
Returns Posts that are no older than | 7 days | 7 days |
HTTP methods supported | GET | GET |
Default request rate limits | 180 requests per 15 min with OAuth 1.0a User Context 450 requests per 15 min with OAuth 2.0 App-Only | Basic: 60 requests per 15 min with OAuth 2.0 App-Only 60 requests per 15 min with OAuth 1.0a User Context 60 requests per 15 min with OAuth 2.0 Authorization Code with PKCE Pro: 450 requests per 15 min with OAuth 2.0 App-Only 180 requests per 15 min with OAuth 1.0a User Context 180 requests per 15 min with OAuth 2.0 Authorization Code with PKCE |
Offers fully unwound URLs | ✔ | |
Maximum Posts per response (default) | 100 (15) | 100 (10) |
Post JSON format | Standard v1.1 format | X API v2 format (determined by fields and expansions request parameters, not backward-compatible with v1.1 formats) To learn more about how to migrate from the Standard v1.1 format to the X API v2 format, please visit our data formats migration guide. |
Supports selecting which fields return in the payload | ✔ | |
Supports requesting and receiving annotations | ✔ | |
Supports requesting specific metrics within Post object | ✔ | |
Supports the conversation_id operator and field | ✔ | |
Provides Post edit history | ✔ | ✔ |
JSON key name for Post data array | statuses | data |
JSON key name for pagination | search_metadata.next_results | meta.next_token |
Supports navigating archive by time range | ✔ | ✔ |
Time resolution of time-based requests | day | second |
Timezone | UTC | UTC |
Request parameters for navigating by time | until | start_time end_time |
Request parameters for navigating by Post ID | since_id max_id | since_id until_id |
Request parameter for pagination | Provides URL-encoded query | next_token |
Requires the use of credentials from a developer App associated with a Project | ✔ |
Full-archive search comparison
The following table compares the various types of full-archive search endpoints:
Description | Enterprise | X API v2 |
---|---|---|
Host domain | https://gnip-api.x.com | https://api.x.com |
Endpoint path | /search/fullarchive/accounts/:account_name/:label | /2/tweets/search/all |
Authentication | Basic auth | OAuth 2.0 App-Only |
Timestamp format | YYYYMMDDHHMM | YYYY-MM-DDTHH:mm:ssZ ISO 8601 / RFC 3339 |
Returns Posts that are no older than | The full archive since March 2006 | The full archive since March 2006 |
HTTP methods supported | GET POST | GET |
Default request rate limits | The per minute rate limit will vary by partner as specified in your contract. 20 requests per sec with Basic auth | 300 requests per 15 min with OAuth 2.0 App-Only 1 requests per 1 sec with OAuth 2.0 App-Only |
Offers fully unwound URLs | ✔ | ✔ |
Posts per response | Maximum: 500 Default: 100 | Maximum: 500 Default: 10 |
Post JSON format | Native Enriched or Activity Streams format | X API v2 format (determined by fields and expansions request parameters) |
Supports selecting which fields return in the payload | ✔ | |
Supports requesting and receiving annotations | ✔ | |
Supports requesting specific metrics within Post object | ✔ | |
Supports the conversation_id operator and field | ✔ | |
Provides Post edit history | ✔ | ✔ |
JSON key name for Post data array | results | data |
JSON key name for pagination | next | meta.next_token |
Time resolution of time-based requests | second | second |
Timezone | UTC | UTC |
Supports navigating archive by Post ID | ✔ | |
Request parameters for navigation by time | fromDate toDate | start_time end_time |
Request parameters for navigating by Post ID | since_id until_id | |
Request parameter for pagination | next_token | next_token |
Requires the use of credentials from a developer App associated with a Project that has Academic Research access | ✔ |
Filtering operator comparison
The four different versions (standard, enterprise, and v2) of search Posts differ in which operators are available, and also have varying levels of operator availability within each version, which are explained below.
Enterprise
- There are no sub-tiers of enterprise operators
X API v2
- **Free: **Available when using any Project
- Basic: Available when using any Project
- Pro: Available when using a Project
- Enterprise: Available when using a Project
You can learn more about each of these sets of operators in their respective guides:
Now that we understand the different operator levels within X API v2, here is the table that maps out operator availability for search Posts (note that if the cell is left blank, the operator is not available):
Search operator | Standard | Enterprise | v2 |
---|---|---|---|
keyword | Available q:keyword | Available | Basic & Pro |
emoji | Available q:😄 | Available | Basic & Pro |
“exact phrase” | Available | Available | Basic & Pro |
# | Available | Available | Basic & Pro |
$ | Available | Available | Pro |
@ | Available | Available | Basic & Pro |
from: | Available | Available | Basic & Pro |
to: | Available | Available | Basic & Pro |
url: | Available | Available | Basic & Pro |
retweets_of: | Available | Basic & Pro | |
context: | Basic & Pro | ||
entity: | Basic & Pro - Only available with recent search | ||
conversation_id: | Basic | ||
place: | Available | Pro | |
place_country: | Available | Pro | |
point_radius: | geocode parameter | Available | Pro |
bounding_box: | Available | Pro | |
is:retweet | filter:retweets | Available | Basic & Pro |
is:reply | Available | Basic & Pro | |
is:quote | Available | Basic & Pro | |
is:verified | Available | Basic & Pro | |
-is:nullcast | Available | Pro | |
has:hashtags | Available | Basic & Pro | |
has:cashtags | Available | Pro | |
has:links | filter:links | Available | Basic & Pro |
has:mentions | Available | Basic & Pro | |
has:media | filter:media | Available | Basic & Pro |
has:images | filter:images, filter:twimg | Available | Basic & Pro |
has:videos | filter:videos filter:native_video | Available | Basic & Pro |
has:geo | Available | Pro | |
lang: | lang - can be used as an operator or a parameter | Available | Basic & Pro |
has:profile_geo | Available | ||
profile_country | Available | ||
profile_locality | Available | ||
profile_region | Available | ||
proximity | Available | ||
:( | Available | ||
:) | Available | ||
? | Available | ||
filter:periscope | Available | ||
list: | Available | Pro | |
filter:replies | Available | ||
filter:pro_video | Available | ||
filter:social | Available | ||
filter:trusted | Available | ||
filter:follows | Available | ||
filter:has_engagement | Available | ||
include:antisocial | Available | ||
include:offensive_user | Available | ||
include:antisocial_offensive_user | Available | ||
include:sensitive_content | Available | ||
source: | Available | ||
min_replies: | Available | ||
min_retweets: | Available | ||
min_faves: | Available | ||
card_name: | Available | ||
card_domain: | Available |
Other migration resources
Check out some sample code for these endpoints
Search Posts: Standard v1.1 to X API v2
Search Posts: Enterprise to X API v2
Standard v1.1 compared to X API v2
If you have been working with the v1.1 search/posts, the goal of this guide is to help you understand the similarities and differences between the standard and X API v2 search Posts endpoint.
- Similarities
- OAuth 1.0a User Context and OAuth 2.0 App-Only
- Support for Post edit history and metadata.
- Differences
-
Endpoint URLs
-
App and Project requirements
-
Response data format
-
Request parameters
-
New query operators
-
AND / OR operator precedence
-
Similarities
OAuth 1.0a User Context and OAuth 2.0 App-Only authentication
The v1.1 search/posts and the X API v2 recent search endpoint support both OAuth 1.0a User Context and OAuth 2.0 App-Only.
Therefore, if you were previously using the standard v1.1 search endpoint you can continue using the same authentication method if you migrate to the X API v2 version.
Depending on your authentication library/package of choice, App-Only authentication is probably the easiest way to get started and can be set with a simple request header. To learn how to generate an App Access Token see this OAuth 2.0 App-Only guide.
If you would like to take advantage of the ability to pull private or advertising metrics with the X API v2 endpoint, you will need to use OAuth 1.0a User Context, and pass the user access tokens related to the user who posted the Post for which you would like to pull metrics.
Support for Post edit history and metadata
Both versions provide metadata that describes any edit history. Check out the search API References and the Post edits fundamentals page for more details.
Differences
Endpoint URLs
-
Standard v1.1 endpoints:
-
X API v2 endpoint:
App and Project requirements
The X API v2 endpoints require that you use credentials from a developer App that is associated to a Project when authenticating your requests. All X API v1.1 endpoints can use credentials from standalone Apps or Apps associated with a Project.
Response data format
One of the biggest differences between standard v1.1 and X API v2 endpoint versions is how you select which fields return in your payload.
For the standard endpoints, you receive many of the response fields by default, and then have the option to use parameters to identify which fields or sets of fields should return in the payload.
The X API v2 version only delivers the Post id and text fields by default. To request any additional fields or objects, you will need to use the fields and expansions parameters. Any Post fields that you request from these endpoints will return in the primary Post object. Any expanded user, media, poll, or place objects and fields will return in an includes object within your response. You can then match any expanded objects back to the Post object by matching the IDs located in both the Post and the expanded object.
We encourage you to read more about these new parameters in their respective guides, or by reading our guide on how to use fields and expansions.
We have also put together a data format migration guide which can help you map standard v1.1 fields to the newer v2 fields. This guide will also provide you the specific expansion and field parameter that you will need to pass with your v2 request to return specific fields.
In addition to the changes in how you request certain fields, X API v2 is also introducing new JSON designs for the objects returned by the APIs, including Post and user objects.
- At the JSON root level, the standard endpoints return Post objects in a statuses array, while X API v2 returns a data array.
- Instead of referring to Retweeted and Quoted “statuses”, X API v2 JSON refers to Retweeted and Quoted Tweets. Many legacy and deprecated fields, such as contributors and user.translator_type are being removed.
- Instead of using both favorites (in Post object) and favourites (in user object), X API v2 uses the term like.
- X is adopting the convention that JSON values with no value (for example, null) are not written to the payload. Post and user attributes are only included if they have non-null values.
We also introduced a new set of fields to the Post object including the following:
- A conversation_id field
- Two new annotations fields, including context and entities
- Several new metrics fields
- A new reply_setting field, which shows you who can reply to a given Post
Request parameters
The following standard v1.1 request parameters have equivalents in X API v2:
Standard search v1.1 | Search Posts v2 |
---|---|
q | query |
start_time (YYYY-MM-DDTHH:mm:ssZ) | |
until (YYYY-MM-DD) | end_time (YYYY-MM-DDTHH:mm:ssZ) |
since_id | since_id |
max_id | until_id |
count | max_results |
Response provides search_metadata.next_results | next_token |
There are also a set of standard search Posts request parameters not supported in X API v2:
Standard v1.1 parameter | Details |
---|---|
geocode | Search Posts at the Basic Access level does not support geo operators. |
locale | With standard search, this was used to specify the language of the query but never fully implemented. |
lang | Search Posts endpoints provide a lang query operator for matching on languages of interest. |
include_entities | Post entities are always included. |
result_type | Search Posts endpoints deliver all matching Posts, regardless of engagement level. |
extended | X API v2 is built from the ground up to support Posts with up to 280 characters. With v2, there is no concept of ‘extended’ Posts. |
Here is an example request that shows the difference between a Standard request and a Search Posts request:
Standard v1.1 | X API v2 |
https://api.x.com/1.1/search/tweets.json?q=snow&count=50 | https://api.x.com/2/tweets/search/recent?query=snow&max_results=50 |
These requests will both return the 50 most recent Posts that contain the keyword snow. The v2 request will return the default id and text fields of the matching Posts. Here is an example of specifying additional Posts and user fields to include in the JSON payload:
X API v2 |
https://api.x.com/2/tweets/search/recent?query=snow&max\_results=50&tweet.fields=id,created\_at,author_id,text,source,entities,attachments&user.fields=id,name,username,description |
New query operators
Search Posts introduces new operators in support of two new X API v2 features:
- Conversation IDs - As conversations unfold on X, a conservation ID will be available to mark Posts that are part of the conversation. All Posts in the conversation will have their conversation_id set to the Post ID that started it.
conversation_id:
- X Annotations provide contextual information about Posts, and include entity and context annotations. Entities are comprised of people, places, products and organizations. Contexts are domains, or topics, that surfaced entities are a part of. For example, people mentioned in a Post may have a context that indicates whether they are an athlete, actor, or politician.
-
context: matches on Posts that have been annotated with a context of interest.
-
entity: matches on Posts that have been annotated with an entity of interest.
-
AND / OR operator precedence
The basic building block for building search queries is the use of OR and AND logical groupings. The standard search API applies ORs before ANDs, while Search Posts endpoints (as well as the premium and enterprise versions) applies ANDs before ORs. This difference is critical when translating queries between the two.
For example, with standard search, if you wanted to match Posts with the keyword ‘storm’ that mention the word ‘colorado’ or the #COwx hashtag, you could do that with the following search query:
storm #COwx OR colorado
With the Search Posts operator precedence, ANDs are applied before ORs. So the above query is equivalent to:
(storm #COwx) OR colorado
However, the above rule would match on any Posts that mentions ‘Colorado’, regardless if the Post mentions ‘storm’ or the #COwx hashtag. In addition it would also match Posts that mentioned both the keyword ‘storm’ and the #COwx hashtag.
To make the query behave as originally intended, the OR clauses need to be grouped together. The translation of the original standard query to Search Posts would be:
storm (#COwx OR colorado)
These two rules have very different matching behavior. For the month of October 2019, the original rule matches over 1,175,000 Posts while the correctly translated rule matches around 5,600 Posts. Be sure to mind your ANDs and ORs, and use parentheses where needed.
cURL requests
The following section displays cURL requests for the standard v1.1 endpoint and its equivalent endpoint in v2.
The requests are made using [OAuth 2.0 App-Only](https://developer.twitter.com(/resources/fundamentals/authentication#app-only-authentication-and-oauth-2-0-bearer-token). In order to run the following cURL requests, you will need to replace ACCESS_TOKEN in the authorization header with your app access token. For v2 endpoints, your app access token must belong to a developer App within a Project.
The response payload returned by the v1.1 endpoint will be different from the response payload returned by the v2 endpoint. With v2, the response will include the default fields, as well as any other fields requested with the fields and expansions parameters. You can use these parameters to request a different set of fields to be returned.
Standard v1.1 GET search/tweets and v2 GET tweets/search/recent endpoints
Enterprise compared to X API v2
Similarities
- Pagination
- Timezone
- Support for Post edit history and metadata.
Differences
- Endpoint URLs
- App and Project requirement
- Available time periods
- Response data format
- HTTP methods
- Request time formats
- Request parameters
- Filtering operators
Similarities
Pagination
While v2 has additional pagination features (new pagination parameters that allow you to navigate using Post IDs with since_id
and until_id
), both enterprise and v2 allow you to paginate using time (fromDate
and toDate
with enterprise, and start_time
and end_time
for v2).
Timezone
As noted in the pagination section, you can navigate different pages of data using time for both enterprise and v2. In both cases, you will be using UTC as the timezone when using these parameters.
Support for Post edit history and metadata
Both versions provide metadata that describes any edit history. Check out the search API References and thePost edits fundamentals page for more details.
Differences
Endpoint URLs
- Enterprise endpoints:
- 30 day -
http://gnip-api.x.com/search/30day/accounts/:account_name/:label.json
- Full-archive -
http://gnip-api.x.com/search/fullarchive/accounts/:account_name/:label.json
- 30 day -
- X API v2 endpoints
- Recent (7 day) -
https://api.x.com/2/tweets/search/recent
- Full-archive -
https://api.x.com/2/tweets/search/all
- Recent (7 day) -
App and Project requirement
The X API v2 endpoints require that you use credentials from a Project when authenticating your requests. All X API v1.1 endpoints can use credentials from standalone Apps or Apps associated with a Project.
Available time periods
Both the enterprise API and X API v2 offer endpoints that allow you to retrieve filtered Post data for the full-archive of Posts.
However, the X API v2 does not offer a 30 day time period endpoint like the enterprise API does. Instead it offers the aforementioned full-archive, or a 7 day time period, which align with the Native Enriched to v2 and Activity Streams to v2 which can help you map enterprise fields to the newer v2 fields. This guide will also provide you the specific expansion and field parameter that you will need to pass with your v2 request to return specific fields.
Response data format
One of the biggest differences between the enterprise response format andX API v2’s format is how you select which fields return in your payload.
For the enterprise Search API, you receive many of the response fields by default, and then have the option to use parameters to identify which fields or sets of fields should return in the payload.
The X API v2 version only delivers the Post id
and text
fields by default. To request any additional fields or objects, you will need to use the fields and expansions parameters. Any Post fields that you request from these endpoints will return in the primary Post object. Any expanded user, media, poll, or place objects and fields will return in an includes
object within your response. You can then match any expanded objects back to the Post object by matching the IDs located in both the Post and the expanded object.
We encourage you to read more about these new parameters in their respective guides, or by reading our guide on how to use fields and expansions.
In addition to the changes in how you request certain fields, X API v2 is also introducing new JSON designs for the objects returned by the APIs, including Post and user objects.
- At the JSON root level, the standard endpoints return Post objects in a
statuses
array, while X API v2 returns adata
array. - Instead of referring to Retweeted and Quoted “statuses”, X API v2 JSON refers to Retweeted and Quoted Tweets. Many legacy and deprecated fields, such as
contributors
anduser.translator_type
are being removed. - Instead of using both
favorites
(in Post object) andfavourites
(in user object), X API v2 uses the term like. - X is adopting the convention that JSON values with no value (for example,
null
) are not written to the payload. Post and user attributes are only included if they have non-null values.
We also introduced a new set of fields to the Post object including the following:
- A conversation_id field
- Two new annotations fields, including context and entities
- Several new metrics fields
- A new
reply_setting
field, which shows you who can reply to a given Post
And one last note. The premium response includes a requestParameters
object at the root level, which contains the parameters that you included in your request. The v2 version instead contains a meta
object that lives at the root level which includes the newest_id
, oldest_id
, result_count
, and next_token
if there is an additional page of results.
HTTP methods
The enterprise version of the API allows you to pass the request as either a POST HTTP method with a JSON body, or a GET HTTP method with a query string.
V2 only allows you to use the GET HTTP method with a query string.
Request time formats
The enterprise version of this endpoint uses the following date/time format in both the pagination parameters and the timePeriod
response field: YYYYMMDDHHmm
The v2 endpoint uses ISO 8601/RFC 3339 date/time format in both the pagination parameters and the start
and end
response fields: YYYY-MM-DDTHH:mm:ssZ
Request parameters
The following is a table of the request parameters for enterprise and X API v2:
Enterprise | Search Posts v2 |
---|---|
query | query |
maxResults | max_results |
fromDate (YYMMDDHHmm) | start_time (YYYY-MM-DDTHH:mm:ssZ) |
toDate (YYMMDDHHmm) | end_time (YYYY-MM-DDTHH:mm:ssZ) |
since_id | |
until_id | |
next | next_token or pagination_token |
Filtering operators
While the operators between enterprise and X API v2 are mostly the same, there are some differences in operator availability and some new operators that were introduced to just the X API v2 version.
To see a full table of the operators that are available for X API v2, enterprise, and even premium and standard, please visit the Search Posts migration landing page.
API reference index
For a complete API reference, please select an endpoint from below.
Recent search
Search for Posts published in the last 7 days | [GET /2/tweets/search/recent](/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent) |
Full-archive search
Only available to those with Pro and Enterprise access
Search the full archive of Posts | [GET /2/tweets/search/all](/x-api/x-api-v2/tweets/search-tweets#get-2-tweets-search-all) |
GET /2/tweets/search/recent
The recent search endpoint returns Tweets from the last seven days that match a search query.
The Tweets returned by this endpoint count towards the Project-level Tweet cap.
Build request with API Explorer ❯
Endpoint URL
https://api.x.com/2/tweets/search/recent
Authentication and rate limits
Authentication methods supported by this endpoint | OAuth 2.0 App-only OAuth 1.0a is also available for this endpoint. OAuth 2.0 Authorization Code with PKCE |
[Rate limit]/resources/fundamentals/rate-limits) | App rate limit (Application-only): 450 requests per 15-minute window shared among all users of your app User rate limit (User context): 180 requests per 15-minute window per each authenticated user |
OAuth 2.0 scopes required by this endpoint
tweet.read users.read |
Learn more about OAuth 2.0 Authorization Code with PKCE |
Query parameters
Name | Type | Description |
---|---|---|
query Required | string | One query for matching Tweets. You can learn how to build this query by reading our build a query guide. If you have Essential or Elevated access, you can use the Basic operators when building your query and can make queries up to 512 characters long. If you have been approved for Academic Research access, you can use all available operators and can make queries up to 1,024 characters long. Learn more about our access levels on the about Twitter API page. |
end_time Optional | date (ISO 8601) | YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). The newest, most recent UTC timestamp to which the Tweets will be provided. Timestamp is in second granularity and is exclusive (for example, 12:00:01 excludes the first second of the minute). By default, a request will return Tweets from as recent as 30 seconds ago if you do not include this parameter. |
expansions Optional | enum (attachments.poll_ids , attachments.media_keys , author_id , edit_history_tweet_ids , entities.mentions.username , geo.place_id , in_reply_to_user_id , referenced_tweets.id , referenced_tweets.id.author_id ) | Expansions enable you to request additional data objects that relate to the originally returned Tweets. Submit a list of desired expansions in a comma-separated list without spaces. The ID that represents the expanded data object will be included directly in the Tweet data object, but the expanded object metadata will be returned within the includes response object, and will also include the ID so that you can match this data object to the original Tweet object. The following data objects can be expanded using this parameter: * The Tweet author’s user object * The user object of the Tweet’s author that the original Tweet is responding to * Any mentioned users’ object * Any referenced Tweets’ author’s user object * Attached media’s object * Attached poll’s object * Attached place’s object * Any referenced Tweets’ object (this includes Tweet objects for previous versions of an edited Tweet) |
max_results Optional | integer | The maximum number of search results to be returned by a request. A number between 10 and 100. By default, a request response will return 10 results. |
media.fields Optional | enum (duration_ms , height , media_key , preview_image_url , type , url , width , public_metrics , non_public_metrics , organic_metrics , promoted_metrics , alt_text , variants ) | This fields parameter enables you to select which specific media fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. The Tweet will only return media fields if the Tweet contains media and if you’ve also included the expansions=attachments.media_keys query parameter in your request. While the media ID will be located in the Tweet object, you will find this ID and all additional media fields in the includes data object. |
next_token Optional | string | This parameter is used to get the next ‘page’ of results. The value used with the parameter is pulled directly from the response provided by the API, and should not be modified. |
place.fields Optional | enum (contained_within , country , country_code , full_name , geo , id , name , place_type ) | This fields parameter enables you to select which specific place fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. The Tweet will only return place fields if the Tweet contains a place and if you’ve also included the expansions=geo.place_id query parameter in your request. While the place ID will be located in the Tweet object, you will find this ID and all additional place fields in the includes data object. |
poll.fields Optional | enum (duration_minutes , end_datetime , id , options , voting_status ) | This fields parameter enables you to select which specific poll fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. The Tweet will only return poll fields if the Tweet contains a poll and if you’ve also included the expansions=attachments.poll_ids query parameter in your request. While the poll ID will be located in the Tweet object, you will find this ID and all additional poll fields in the includes data object. |
since_id Optional | string | Returns results with a Tweet ID greater than (that is, more recent than) the specified ID. The ID specified is exclusive and responses will not include it. If included with the same request as a start_time parameter, only since_id will be used. |
sort_order Optional | enum (recency , relevancy ) | This parameter is used to specify the order in which you want the Tweets returned. By default, a request will return the most recent Tweets first (sorted by recency). |
start_time Optional | date (ISO 8601) | YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). The oldest UTC timestamp (from most recent seven days) from which the Tweets will be provided. Timestamp is in second granularity and is inclusive (for example, 12:00:01 includes the first second of the minute). If included with the same request as a since_id parameter, only since_id will be used. By default, a request will return Tweets from up to seven days ago if you do not include this parameter. |
tweet.fields Optional | enum (attachments , author_id , context_annotations , conversation_id , created_at , edit_controls , entities , geo , id , in_reply_to_user_id , lang , non_public_metrics , public_metrics , organic_metrics , promoted_metrics , possibly_sensitive , referenced_tweets , reply_settings , source , text , withheld ) | This fields parameter enables you to select which specific Tweet fields will deliver in each returned Tweet object. Specify the desired fields in a comma-separated list without spaces between commas and fields. You can also pass the expansions=referenced_tweets.id expansion to return the specified fields for both the original Tweet and any included referenced Tweets. The requested Tweet fields will display in both the original Tweet data object, as well as in the referenced Tweet expanded data object that will be located in the includes data object. |
until_id Optional | string | Returns results with a Tweet ID less than (that is, older than) the specified ID. The ID specified is exclusive and responses will not include it. |
user.fields Optional | enum (created_at , description , entities , id , location , most_recent_tweet_id , name , pinned_tweet_id , profile_image_url , protected , public_metrics , url , username , verified , verified_type , withheld ) | This fields parameter enables you to select which specific user fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. While the user ID will be located in the original Tweet object, you will find this ID and all additional user fields in the includes data object. You must also pass one of the user expansions to return the desired user fields: * expansions=author_id * expansions=entities.mentions.username * expansions=in_reply_to_user_id * expansions=referenced_tweets.id.author_id |
Example code with offical SDKs
- TypeScript (Default fields)
- TypeScript (Optional fields)
- Java (Default fields)
- Java (Optional fields)
Example responses
Response fields
Name | Type | Description |
---|---|---|
id Default | string | Unique identifier of this Tweet. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. |
text Default | string | The content of the Tweet. To return this field, add tweet.fields=text in the request’s query parameter. |
created_at | date (ISO 8601) | Creation time of the Tweet. To return this field, add tweet.fields=created_at in the request’s query parameter. |
author_id | string | Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. You can obtain the expanded object in includes.users by adding expansions=author_id in the request’s query parameter. |
edit_history_tweet_ids Default | array | Unique identifiers indicating all versions of an edited Tweet. For Tweets with no edits, there will be one ID. For Tweets with an edit history, there will be multiple IDs, arranged in ascending order reflecting the order of edit, with the most recent version in the last position of the array. |
edit_controls | object | Indicates if a Tweet is eligible for edit, how long it is editable for, and the number of remaining edits. The is_edit_eligible field indicates if a Tweet was eligible for edit when published. This field is not dynamic and won’t toggle from True to False when a Tweet reaches its editable time limit, or maximum number of edits. The following Tweet features will cause this field to be false:* Tweet is promoted * Tweet has a poll * Tweet is a non-self-thread reply * Tweet is a Retweet (note that Quote Tweets are eligible for edit) * Tweet is nullcast * Community Tweet * Superfollow Tweet * Collaborative Tweet { <br/> "edit_controls": { <br/> "is_edit_eligible": true, <br/> "editable_until": "2022-08-21 09:35:20.311", <br/> "edits_remaining": 4 <br/> } <br/>} <br/> Editable Tweets can be edited for the first 30 minutes after creation and can be edited up to five times. To return this field, add tweet.fields=edit_controls in the request’s query parameter. |
note_tweet | object | Information about Tweets with more than 280 characters. To return this field, add tweet.fields=note_tweet in the request’s query parameter. |
conversation_id | string | The Tweet ID of the original Tweet of the conversation (which includes direct replies, replies of replies). To return this field, add tweet.fields=conversation_id in the request’s query parameter. |
in_reply_to_user_id | string | If this Tweet is a Reply, indicates the user ID of the parent Tweet’s author. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. You can obtain the expanded object in includes.users by adding expansions=in_reply_to_user_id in the request’s query parameter. |
referenced_tweets | array | A list of Tweets this Tweet refers to. For example, if the parent Tweet is a Retweet, a Retweet with comment (also known as Quoted Tweet) or a Reply, it will include the related Tweet referenced to by its parent. To return this field, add tweet.fields=referenced_tweets in the request’s query parameter. |
referenced_tweets.type | enum (retweeted , quoted , replied_to ) | Indicates the type of relationship between this Tweet and the Tweet returned in the response: retweeted (this Tweet is a Retweet), quoted (a Retweet with comment, also known as Quoted Tweet), or replied_to (this Tweet is a reply). |
referenced_tweets.id | string | The unique identifier of the referenced Tweet. You can obtain the expanded object in includes.tweets by adding expansions=referenced_tweets.id in the request’s query parameter. |
attachments | object | Specifies the type of attachments (if any) present in this Tweet. To return this field, add tweet.fields=attachments in the request’s query parameter. |
attachments.media_keys | array | List of unique identifiers of media attached to this Tweet. These identifiers use the same media key format as those returned by the Media Library. You can obtain the expanded object in includes.media by adding expansions=attachments.media_keys in the request’s query parameter. |
attachments.poll_ids | array | List of unique identifiers of polls present in the Tweets returned. These are returned as a string in order to avoid complications with languages and tools that cannot handle large integers. You can obtain the expanded object in includes.polls by adding expansions=attachments.polls_ids in the request’s query parameter. |
geo | object | Contains details about the location tagged by the user in this Tweet, if they specified one. To return this field, add tweet.fields=geo in the request’s query parameter. |
geo.coordinates | object | Contains details about the coordinates of the location tagged by the user in this Tweet, if they specified one. To return this field, add tweet.fields=geo.coordinates in the request’s query parameter. |
geo.coordinates.type | string | Describes the type of coordinate. The only value supported at present is Point . |
geo.coordinates.coordinates | array | A pair of decimal values representing the precise location of the user (latitude, longitude). This value be null unless the user explicitly shared their precise location. |
geo.place_id | string | The unique identifier of the place, if this is a point of interest tagged in the Tweet. You can obtain the expanded object in includes.places by adding expansions=geo.place_id in the request’s query parameter. |
context_annotations | array | Contains context annotations for the Tweet. To return this field, add tweet.fields=context_annotations in the request’s query parameter. |
context_annotations.domain | object | Contains elements which identify detailed information regarding the domain classification based on Tweet text. |
context_annotations.domain.id | string | Contains the numeric value of the domain. |
context_annotations.domain.name | string | Domain name based on the Tweet text. |
context_annotations.domain.description | string | Long form description of domain classification. |
context_annotations.entity | object | Contains elements which identify detailed information regarding the domain classification bases on Tweet text. |
context_annotations.entity.id | string | Unique value which correlates to an explicitly mentioned Person, Place, Product or Organization |
context_annotations.entity.name | string | Name or reference of entity referenced in the Tweet. |
context_annotations.entity.description | string | Additional information regarding referenced entity. |
entities | object | Contains details about text that has a special meaning in a Tweet. To return this field, add tweet.fields=entities in the request’s query parameter. |
entities.annotations | array | Contains details about annotations relative to the text within a Tweet. |
entities.annotations.start | integer | The start position (zero-based) of the text used to annotate the Tweet. All start indices are inclusive. |
entities.annotations.end | integer | The end position (zero based) of the text used to annotate the Tweet. While all other end indices are exclusive, this one is inclusive. |
entities.annotations.probability | number | The confidence score for the annotation as it correlates to the Tweet text. |
entities.annotations.type | string | The description of the type of entity identified when the Tweet text was interpreted. |
entities.annotations.normalized_text | string | The text used to determine the annotation type. |
entities.urls | array | Contains details about text recognized as a URL. |
entities.urls.start | integer | The start position (zero-based) of the recognized URL within the Tweet. All start indices are inclusive. |
entities.urls.end | integer | The end position (zero-based) of the recognized URL within the Tweet. This end index is exclusive. |
entities.urls.url | string | The URL in the format tweeted by the user. |
entities.urls.expanded_url | string | The fully resolved URL. |
entities.urls.display_url | string | The URL as displayed in the Twitter client. |
entities.urls.unwound_url | string | The full destination URL. |
entities.hashtags | array | Contains details about text recognized as a Hashtag. |
entities.hashtags.start | integer | The start position (zero-based) of the recognized Hashtag within the Tweet. All start indices are inclusive. |
entities.hashtags.end | integer | The end position (zero-based) of the recognized Hashtag within the Tweet. This end index is exclusive. |
entities.hashtags.tag | string | The text of the Hashtag. |
entities.mentions | array | Contains details about text recognized as a user mention. |
entities.mentions.start | integer | The start position (zero-based) of the recognized user mention within the Tweet. All start indices are inclusive. |
entities.mentions.end | integer | The end position (zero-based) of the recognized user mention within the Tweet. This end index is exclusive. |
entities.mentions.username | string | The part of text recognized as a user mention. You can obtain the expanded object in includes.users by adding expansions=entities.mentions.username in the request’s query parameter. |
entities.cashtags | array | Contains details about text recognized as a Cashtag. |
entities.cashtags.start | integer | The start position (zero-based) of the recognized Cashtag within the Tweet. All start indices are inclusive. |
entities.cashtags.end | integer | The end position (zero-based) of the recognized Cashtag within the Tweet. This end index is exclusive. |
entities.cashtags.tag | string | The text of the Cashtag. |
withheld | object | Contains withholding details for withheld content. To return this field, add tweet.fields=withheld in the request’s query parameter. |
withheld.copyright | boolean | Indicates if the content is being withheld for on the basis of copyright infringement. |
withheld.country_codes | array | Provides a list of countries where this content is not available. |
withheld.scope | enum (tweet , user ) | Indicates whether the content being withheld is a Tweet or a user. |
note_tweet | object | Information for Tweets longer than 280 characters. To return this field, add tweet.fields=note_tweet in the request’s query parameter. |
note_tweet.text | string | The text for Tweets longer than 280 characters. |
note_tweet.entities | object | Contains details about text that has a special meaning in a Tweet. |
note_tweet.entities.urls | array | Contains details about text recognized as a URL. |
note_tweet.entities.mentions | array | Contains details about text recognized as a user mention. |
note_tweet.entities.hashtags | array | Contains details about text recognized as a Hashtag. |
note_tweet.entities.cashtags | array | Contains details about text recognized as a Cashtag. |
public_metrics | object | Engagement metrics for the Tweet at the time of the request. To return this field, add tweet.fields=public_metrics in the request’s query parameter. |
public_metrics.retweet_count | integer | Number of times this Tweet has been Retweeted. |
public_metrics.reply_count | integer | Number of Replies of this Tweet. |
public_metrics.like_count | integer | Number of Likes of this Tweet. |
public_metrics.quote_count | integer | Number of times this Tweet has been Retweeted with a comment (also known as Quote). |
public_metrics.impression_count | integer | Number of times this Tweet has been viewed. |
public_metrics.bookmark_count | integer | Number of times this Tweet has been bookmarked. |
non_public_metrics | object | Non-public engagement metrics for the Tweet at the time of the request. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. To return this field, add tweet.fields=non_public_metrics in the request’s query parameter. |
non_public_metrics.impression_count | integer | Number of times the Tweet has been viewed. This requires the use of OAuth 2.0 User Context authentication. |
non_public_metrics.url_link_clicks | integer | Number of times a user clicks on a URL link or URL preview card in a Tweet. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
non_public_metrics.user_profile_clicks | integer | Number of times a user clicks the following portions of a Tweet - display name, user name, profile picture. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
organic_metrics | object | Organic engagement metrics for the Tweet at the time of the request. Requires user context authentication. |
organic_metrics.impression_count | integer | Number of times the Tweet has been viewed organically. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
organic_metrics.url_link_clicks | integer | Number of times a user clicks on a URL link or URL preview card in a Tweet organically. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
organic_metrics.user_profile_clicks | integer | Number of times a user clicks the following portions of a Tweet organically - display name, user name, profile picture. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
organic_metrics.retweet_count | integer | Number of times the Tweet has been Retweeted organically. |
organic_metrics.reply_count | integer | Number of replies the Tweet has received organically. |
organic_metrics.like_count | integer | Number of likes the Tweet has received organically. |
promoted_metrics | object | Engagement metrics for the Tweet at the time of the request in a promoted context. Requires user context authentication. |
promoted_metrics.impression_count | integer | Number of times the Tweet has been viewed when that Tweet is being promoted. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
promoted_metrics.url_link_clicks | integer | Number of times a user clicks on a URL link or URL preview card in a Tweet when it is being promoted. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
promoted_metrics.user_profile_clicks | integer | Number of times a user clicks the following portions of a Tweet when it is being promoted - display name, user name, profile picture. This is a private metric, and requires the use of OAuth 2.0 User Context authentication. |
promoted_metrics.retweet_count | integer | Number of times this Tweet has been Retweeted when that Tweet is being promoted. |
promoted_metrics.reply_count | integer | Number of Replies to this Tweet when that Tweet is being promoted. |
promoted_metrics.like_count | integer | Number of Likes of this Tweet when that Tweet is being promoted. |
possibly_sensitive | boolean | Indicates if this Tweet contains URLs marked as sensitive, for example content suitable for mature audiences. To return this field, add tweet.fields=possibly_sensitive in the request’s query parameter. |
lang | string | Language of the Tweet, if detected by Twitter. Returned as a BCP47 language tag. To return this field, add tweet.fields=lang in the request’s query parameter. |
reply_settings | string | Shows who can reply to this Tweet. Fields returned are everyone , mentionedUsers , and following . To return this field, add tweet.fields=reply_settings in the request’s query parameter. |
source | string | The name of the app the user Tweeted from. To return this field, add tweet.fields=source in the request’s query parameter. |
includes | object | If you include an [expansion](/x-api/x-api-v2/fundamentals/expansions) parameter, the referenced objects will be returned if available. |
includes.tweets | array | When including the expansions=referenced_tweets.id parameter, this includes a list of referenced Retweets, Quoted Tweets, or replies in the form of Tweet objects with their default fields and any additional fields requested using the tweet.fields parameter, assuming there is a referenced Tweet present in the returned Tweet(s). Similarly, when including the expansions=edit_history_tweet_ids parameter, a Tweet’s edit history will be referenced in the form of Tweet objects. |
includes.users | array | When including the expansions=author_id parameter, this includes a list of referenced Tweet authors in the form of user objects with their default fields and any additional fields requested using the user.fields parameter. |
includes.places | array | When including the expansions=geo.place_id parameter, this includes a list of referenced places in Tweets in the form of place objects with their default fields and any additional fields requested using the place.fields parameter, assuming there is a place present in the returned Tweet(s). |
includes.media | array | When including the expansions=attachments.media_keys parameter, this includes a list of images, videos, and GIFs included in Tweets in the form of media objects with their default fields and any additional fields requested using the media.fields parameter, assuming there is a media attachment present in the returned Tweet(s). |
includes.polls | string | When including the expansions=attachments.poll_ids parameter, this includes a list of polls that are attached to Tweets in the form of poll objects with their default fields and any additional fields requested using the poll.fields parameter, assuming there is a poll present in the returned Tweet(s). |
meta Default | object | This object contains information about the number of users returned in the current request and pagination details. |
meta.count Default | integer | The number of Tweet results returned in the response. |
meta.newest_id Default | string | The Tweet ID of the most recent Tweet returned in the response. |
meta.oldest_id Default | string | The Tweet ID of the oldest Tweet returned in the response. |
meta.next_token | string | A value that encodes the next ‘page’ of results that can be requested, via the next_token request parameter. |
errors | object | Contains details about errors that affected any of the requested Tweets. See Status codes and error messages for more details. |
GET /2/tweets/search/all
The full-archive search endpoint returns the complete history of public Tweets matching a search query; since the first Tweet was created March 26, 2006.
The Tweets returned by this endpoint count towards the Project-level Tweet cap.
Endpoint URL
https://api.x.com/2/tweets/search/all
Authentication and rate limits
Authentication methods supported by this endpoint | OAuth 2.0 App-only |
[Rate limit]/resources/fundamentals/rate-limits) | App rate limit (Application-only): 300 requests per 15-minute window shared among all users of your app App rate limit (Application-only): 1 per second shared among all users of your app |
Query parameters
Name | Type | Description |
---|---|---|
query Required | string | One query for matching Tweets. You can learn how to build this query by reading our build a query guide.You can use all available operators and can make queries up to 1,024 characters long. |
end_time Optional | date (ISO 8601) | YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). Used with start_time . The newest, most recent UTC timestamp to which the Tweets will be provided. Timestamp is in second granularity and is exclusive (for example, 12:00:01 excludes the first second of the minute). If used without start_time , Tweets from 30 days before end_time will be returned by default. If not specified, end_time will default to [now - 30 seconds]. |
expansions Optional | enum (attachments.poll_ids , attachments.media_keys , author_id , edit_history_tweet_ids , entities.mentions.username , geo.place_id , in_reply_to_user_id , referenced_tweets.id , referenced_tweets.id.author_id ) | Expansions enable you to request additional data objects that relate to the originally returned Tweets. Submit a list of desired expansions in a comma-separated list without spaces. The ID that represents the expanded data object will be included directly in the Tweet data object, but the expanded object metadata will be returned within the includes response object, and will also include the ID so that you can match this data object to the original Tweet object. The following data objects can be expanded using this parameter: * The Tweet author’s user object * The user object of the Tweet’s author that the original Tweet is responding to * Any mentioned users’ object * Any referenced Tweets’ author’s user object * Attached media’s object * Attached poll’s object * Attached place’s object * Any referenced Tweets’ object (this includes Tweet objects for previous versions of an edited Tweet) |
max_results Optional | integer | The maximum number of search results to be returned by a request. A number between 10 and the system limit (currently 500). By default, a request response will return 10 results. |
media.fields Optional | enum (duration_ms , height , media_key , preview_image_url , type , url , width , public_metrics , alt_text , variants ) | This fields parameter enables you to select which specific media fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. The Tweet will only return media fields if the Tweet contains media and if you’ve also included the expansions=attachments.media_keys query parameter in your request. While the media ID will be located in the Tweet object, you will find this ID and all additional media fields in the includes data object. |
next_token Optional | string | This parameter is used to get the next ‘page’ of results. The value used with the parameter is pulled directly from the response provided by the API, and should not be modified. You can learn more by visiting our page on pagination. |
place.fields Optional | enum (contained_within , country , country_code , full_name , geo , id , name , place_type ) | This fields parameter enables you to select which specific place fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. The Tweet will only return place fields if the Tweet contains a place and if you’ve also included the expansions=geo.place_id query parameter in your request. While the place ID will be located in the Tweet object, you will find this ID and all additional place fields in the includes data object. |
poll.fields Optional | enum (duration_minutes , end_datetime , id , options , voting_status ) | This fields parameter enables you to select which specific poll fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. The Tweet will only return poll fields if the Tweet contains a poll and if you’ve also included the expansions=attachments.poll_ids query parameter in your request. While the poll ID will be located in the Tweet object, you will find this ID and all additional poll fields in the includes data object. |
since_id Optional | string | Returns results with a Tweet ID greater than (for example, more recent than) the specified ID. The ID specified is exclusive and responses will not include it. If included with the same request as a start_time parameter, only since_id will be used. |
sort_order Optional | enum (recency , relevancy ) | This parameter is used to specify the order in which you want the Tweets returned. By default, a request will return the most recent Tweets first (sorted by recency). |
start_time Optional | date (ISO 8601) | YYYY-MM-DDTHH:mm:ssZ (ISO 8601/RFC 3339). The oldest UTC timestamp from which the Tweets will be provided. Timestamp is in second granularity and is inclusive (for example, 12:00:01 includes the first second of the minute). By default, a request will return Tweets from up to 30 days ago if you do not include this parameter. |
tweet.fields Optional | enum (attachments , author_id , context_annotations , conversation_id , created_at , edit_controls , entities , geo , id , in_reply_to_user_id , lang , public_metrics , possibly_sensitive , referenced_tweets , reply_settings , source , text , withheld ) | This fields parameter enables you to select which specific Tweet fields will deliver in each returned Tweet object. Specify the desired fields in a comma-separated list without spaces between commas and fields. You can also pass the expansions=referenced_tweets.id expansion to return the specified fields for both the original Tweet and any included referenced Tweets. The requested Tweet fields will display in both the original Tweet data object, as well as in the referenced Tweet expanded data object that will be located in the includes data object. |
until_id Optional | string | Returns results with a Tweet ID less than (that is, older than) the specified ID. Used with since_id . The ID specified is exclusive and responses will not include it. |
user.fields Optional | enum (created_at , description , entities , id , location , most_recent_tweet_id , name , pinned_tweet_id , profile_image_url , protected , public_metrics , url , username , verified , verified_type , withheld ) | This fields parameter enables you to select which specific user fields will deliver in each returned Tweet. Specify the desired fields in a comma-separated list without spaces between commas and fields. While the user ID will be located in the original Tweet object, you will find this ID and all additional user fields in the includes data object. You must also pass one of the user expansions to return the desired user fields: * expansions=author_id * expansions=entities.mentions.username * expansions=in_reply_to_user_id * expansions=referenced_tweets.id.author_id |
Example code with offical SDKs
- TypeScript (Default fields)
- TypeScript (Optional fields)
- Java (Default fields)
- Java (Optional fields)
Example responses
Response fields
Name | Type | Description |
---|---|---|
id Default | string | Unique identifier of this Tweet. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. |
text Default | string | The content of the Tweet. To return this field, add tweet.fields=text in the request’s query parameter. |
created_at | date (ISO 8601) | Creation time of the Tweet. To return this field, add tweet.fields=created_at in the request’s query parameter. |
author_id | string | Unique identifier of this user. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. You can obtain the expanded object in includes.users by adding expansions=author_id in the request’s query parameter. |
edit_history_tweet_ids Default | array | Unique identifiers indicating all versions of an edited Tweet. For Tweets with no edits, there will be one ID. For Tweets with an edit history, there will be multiple IDs, arranged in ascending order reflecting the order of edit, with the most recent version in the last position of the array. |
edit_controls | object | Indicates if a Tweet is eligible for edit, how long it is editable for, and the number of remaining edits. The is_edit_eligible field indicates if a Tweet was eligible for edit when published. This field is not dynamic and won’t toggle from True to False when a Tweet reaches its editable time limit, or maximum number of edits. The following Tweet features will cause this field to be false:* Tweet is promoted * Tweet has a poll * Tweet is a non-self-thread reply * Tweet is a Retweet (note that Quote Tweets are eligible for edit) * Tweet is nullcast * Community Tweet * Superfollow Tweet * Collaborative Tweet { <br/> "edit_controls": { <br/> "is_edit_eligible": true, <br/> "editable_until": "2022-08-21 09:35:20.311", <br/> "edits_remaining": 4 <br/> } <br/>} <br/> Editable Tweets can be edited for the first 30 minutes after creation and can be edited up to five times. To return this field, add tweet.fields=edit_controls in the request’s query parameter. |
conversation_id | string | The Tweet ID of the original Tweet of the conversation (which includes direct replies, replies of replies). To return this field, add tweet.fields=conversation_id in the request’s query parameter. |
note_tweet | object | Information about Tweets with more than 280 characters. To return this field, add tweet.fields=note_tweet in the request’s query parameter. |
in_reply_to_user_id | string | If this Tweet is a Reply, indicates the user ID of the parent Tweet’s author. This is returned as a string in order to avoid complications with languages and tools that cannot handle large integers. You can obtain the expanded object in includes.users by adding expansions=in_reply_to_user_id in the request’s query parameter. |
referenced_tweets | array | A list of Tweets this Tweet refers to. For example, if the parent Tweet is a Retweet, a Retweet with comment (also known as Quoted Tweet) or a Reply, it will include the related Tweet referenced to by its parent. To return this field, add tweet.fields=referenced_tweets in the request’s query parameter. |
referenced_tweets.type | enum (retweeted , quoted , replied_to ) | Indicates the type of relationship between this Tweet and the Tweet returned in the response: retweeted (this Tweet is a Retweet), quoted (a Retweet with comment, also known as Quoted Tweet), or replied_to (this Tweet is a reply). |
referenced_tweets.id | string | The unique identifier of the referenced Tweet. You can obtain the expanded object in includes.tweets by adding expansions=referenced_tweets.id in the request’s query parameter. |
attachments | object | Specifies the type of attachments (if any) present in this Tweet. To return this field, add tweet.fields=attachments in the request’s query parameter. |
attachments.media_keys | array | List of unique identifiers of media attached to this Tweet. These identifiers use the same media key format as those returned by the Media Library. You can obtain the expanded object in includes.media by adding expansions=attachments.media_keys in the request’s query parameter. |
attachments.poll_ids | array | List of unique identifiers of polls present in the Tweets returned. These are returned as a string in order to avoid complications with languages and tools that cannot handle large integers. You can obtain the expanded object in includes.polls by adding expansions=attachments.polls_ids in the request’s query parameter. |
geo | object | Contains details about the location tagged by the user in this Tweet, if they specified one. To return this field, add tweet.fields=geo in the request’s query parameter. |
geo.coordinates | object | Contains details about the coordinates of the location tagged by the user in this Tweet, if they specified one. To return this field, add tweet.fields=geo.coordinates in the request’s query parameter. |
geo.coordinates.type | string | Describes the type of coordinate. The only value supported at present is Point . |
geo.coordinates.coordinates | array | A pair of decimal values representing the precise location of the user (latitude, longitude). This value be null unless the user explicitly shared their precise location. |
geo.place_id | string | The unique identifier of the place, if this is a point of interest tagged in the Tweet. You can obtain the expanded object in includes.places by adding expansions=geo.place_id in the request’s query parameter. |
context_annotations | array | Contains context annotations for the Tweet. To return this field, add tweet.fields=context_annotations in the request’s query parameter. |
context_annotations.domain | object | Contains elements which identify detailed information regarding the domain classification based on Tweet text. |
context_annotations.domain.id | string | Contains the numeric value of the domain. |
context_annotations.domain.name | string | Domain name based on the Tweet text. |
context_annotations.domain.description | string | Long form description of domain classification. |
context_annotations.entity | object | Contains elements which identify detailed information regarding the domain classification bases on Tweet text. |
context_annotations.entity.id | string | Unique value which correlates to an explicitly mentioned Person, Place, Product or Organization |
context_annotations.entity.name | string | Name or reference of entity referenced in the Tweet. |
context_annotations.entity.description | string | Additional information regarding referenced entity. |
entities | object | Contains details about text that has a special meaning in a Tweet. To return this field, add tweet.fields=entities in the request’s query parameter. |
entities.annotations | array | Contains details about annotations relative to the text within a Tweet. |
entities.annotations.start | integer | The start position (zero-based) of the text used to annotate the Tweet. All start indices are inclusive. |
entities.annotations.end | integer | The end position (zero based) of the text used to annotate the Tweet. While all other end indices are exclusive, this one is inclusive. |
entities.annotations.probability | number | The confidence score for the annotation as it correlates to the Tweet text. |
entities.annotations.type | string | The description of the type of entity identified when the Tweet text was interpreted. |
entities.annotations.normalized_text | string | The text used to determine the annotation type. |
entities.urls | array | Contains details about text recognized as a URL. |
entities.urls.start | integer | The start position (zero-based) of the recognized URL within the Tweet. All start indices are inclusive. |
entities.urls.end | integer | The end position (zero-based) of the recognized URL within the Tweet. This end index is exclusive. |
entities.urls.url | string | The URL in the format tweeted by the user. |
entities.urls.expanded_url | string | The fully resolved URL. |
entities.urls.display_url | string | The URL as displayed in the Twitter client. |
entities.urls.unwound_url | string | The full destination URL. |
entities.hashtags | array | Contains details about text recognized as a Hashtag. |
entities.hashtags.start | integer | The start position (zero-based) of the recognized Hashtag within the Tweet. All start indices are inclusive. |
entities.hashtags.end | integer | The end position (zero-based) of the recognized Hashtag within the Tweet. This end index is exclusive. |
entities.hashtags.tag | string | The text of the Hashtag. |
entities.mentions | array | Contains details about text recognized as a user mention. |
entities.mentions.start | integer | The start position (zero-based) of the recognized user mention within the Tweet. All start indices are inclusive. |
entities.mentions.end | integer | The end position (zero-based) of the recognized user mention within the Tweet. This end index is exclusive. |
entities.mentions.username | string | The part of text recognized as a user mention. You can obtain the expanded object in includes.users by adding expansions=entities.mentions.username in the request’s query parameter. |
entities.cashtags | array | Contains details about text recognized as a Cashtag. |
entities.cashtags.start | integer | The start position (zero-based) of the recognized Cashtag within the Tweet. All start indices are inclusive. |
entities.cashtags.end | integer | The end position (zero-based) of the recognized Cashtag within the Tweet. This end index is exclusive. |
entities.cashtags.tag | string | The text of the Cashtag. |
withheld | object | Contains withholding details for withheld content. To return this field, add tweet.fields=withheld in the request’s query parameter. |
withheld.copyright | boolean | Indicates if the content is being withheld for on the basis of copyright infringement. |
withheld.country_codes | array | Provides a list of countries where this content is not available. |
withheld.scope | enum (tweet , user ) | Indicates whether the content being withheld is a Tweet or a user. |
note_tweet | object | Information for Tweets longer than 280 characters. To return this field, add tweet.fields=note_tweet in the request’s query parameter. |
note_tweet.text | string | The text for Tweets longer than 280 characters. |
note_tweet.entities | object | Contains details about text that has a special meaning in a Tweet. |
note_tweet.entities.urls | array | Contains details about text recognized as a URL. |
note_tweet.entities.mentions | array | Contains details about text recognized as a user mention. |
note_tweet.entities.hashtags | array | Contains details about text recognized as a Hashtag. |
note_tweet.entities.cashtags | array | Contains details about text recognized as a Cashtag. |
public_metrics | object | Engagement metrics for the Tweet at the time of the request. To return this field, add tweet.fields=public_metrics in the request’s query parameter. |
public_metrics.retweet_count | integer | Number of times this Tweet has been Retweeted. |
public_metrics.reply_count | integer | Number of Replies of this Tweet. |
public_metrics.like_count | integer | Number of Likes of this Tweet. |
public_metrics.quote_count | integer | Number of times this Tweet has been Retweeted with a comment (also known as Quote). |
public_metrics.impression_count | integer | Number of times this Tweet has been viewed. |
public_metrics.bookmark_count | integer | Number of times this Tweet has been bookmarked. |
possibly_sensitive | boolean | Indicates if this Tweet contains URLs marked as sensitive, for example content suitable for mature audiences. To return this field, add tweet.fields=possibly_sensitive in the request’s query parameter. |
lang | string | Language of the Tweet, if detected by Twitter. Returned as a BCP47 language tag. To return this field, add tweet.fields=lang in the request’s query parameter. |
reply_settings | string | Shows who can reply to this Tweet. Fields returned are everyone , mentionedUsers , and following . To return this field, add tweet.fields=reply_settings in the request’s query parameter. |
source | string | The name of the app the user Tweeted from. To return this field, add tweet.fields=source in the request’s query parameter. |
includes | object | If you include an [expansion](/x-api/x-api-v2/fundamentals/expansions) parameter, the referenced objects will be returned if available. |
includes.tweets | array | When including the expansions=referenced_tweets.id parameter, this includes a list of referenced Retweets, Quoted Tweets, or replies in the form of Tweet objects with their default fields and any additional fields requested using the tweet.fields parameter, assuming there is a referenced Tweet present in the returned Tweet(s). Similarly, when including the expansions=edit_history_tweet_ids parameter, a Tweet’s edit history will be referenced in the form of Tweet objects. |
includes.users | array | When including the expansions=author_id parameter, this includes a list of referenced Tweet authors in the form of user objects with their default fields and any additional fields requested using the user.fields parameter. |
includes.places | array | When including the expansions=geo.place_id parameter, this includes a list of referenced places in Tweets in the form of place objects with their default fields and any additional fields requested using the place.fields parameter, assuming there is a place present in the returned Tweet(s). |
includes.media | array | When including the expansions=attachments.media_keys parameter, this includes a list of images, videos, and GIFs included in Tweets in the form of media objects with their default fields and any additional fields requested using the media.fields parameter, assuming there is a media attachment present in the returned Tweet(s). |
includes.polls | string | When including the expansions=attachments.poll_ids parameter, this includes a list of polls that are attached to Tweets in the form of poll objects with their default fields and any additional fields requested using the poll.fields parameter, assuming there is a poll present in the returned Tweet(s). |
meta Default | object | This object contains information about the number of users returned in the current request and pagination details. |
meta.count Default | integer | The number of Tweet results returned in the response. |
meta.newest_id Default | string | The Tweet ID of the most recent Tweet returned in the response. |
meta.oldest_id Default | string | The Tweet ID of the oldest Tweet returned in the response. |
meta.next_token | string | A value that encodes the next ‘page’ of results that can be requested, via the next_token request parameter. |
errors | object | Contains details about errors that affected any of the requested Tweets. See Status codes and error messages for more details. |