Authentication
All X API v2 endpoints require authentication. Choose the method that fits your use case:App-Only authentication
For public Post data, use a Bearer Token:cURL
User Context authentication
To access private metrics, authenticate on behalf of the Post author:Fields and expansions
The X API v2 returns minimal data by default. Usefields and expansions to request exactly what you need.
Default response
Available fields
tweet.fields
tweet.fields
media.fields (requires attachments.media_keys expansion)
media.fields (requires attachments.media_keys expansion)
Example with fields
cURL
Post edits
Posts can be edited up to 5 times within 30 minutes of creation.How it works
- Each edit creates a new Post ID
edit_history_tweet_idscontains all versions (oldest first)- The endpoint always returns the most recent version
Example response
Error handling
Common errors
Deleted or protected Posts
If a Post is deleted or from a protected account you don’t follow:- Single Post lookup returns
404 - Multi-Post lookup omits the Post from results with an
errorsarray
Best practices
Batch requests
Use the multi-Post endpoint to fetch up to 100 Posts at once, reducing API calls.
Request only needed fields
Specify only the fields you need to minimize response size and processing time.
Cache responses
Cache Post data locally to reduce repeated requests for the same content.
Handle edits
For real-time apps, consider re-fetching Posts after the 30-minute edit window.
Next steps
API Reference
Complete endpoint documentation
Data dictionary
All available objects and fields
Sample code
Working code examples
Error handling
Handle errors gracefully