Authentication
All X API v2 endpoints require authentication. Choose the method that fits your use case:App-Only authentication
For public user data, use a Bearer Token:cURL
User Context authentication
Required for the authenticated user endpoint (/2/users/me):
cURL
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
user.fields
user.fields
tweet.fields (requires pinned_tweet_id expansion)
tweet.fields (requires pinned_tweet_id expansion)
Example with fields
cURL
Response with expansions
Fields and expansions guide
Learn more about customizing responses
Batch lookups
Look up multiple users in a single request:cURL (by IDs)
Error handling
Common errors
Suspended or deleted users
If a user is suspended or deleted:- Single user lookup returns
404 - Multi-user lookup omits the user from results with an
errorsarray
Protected users
For protected accounts you don’t follow:- Basic info (id, name, username) is available
- Protected content (pinned Post) may be restricted
protected: trueindicates the account status
Best practices
Batch requests
Use multi-user endpoints to fetch up to 100 users at once, reducing API calls.
Request only needed fields
Specify only the fields you need to minimize response size.
Cache user data
Cache user profiles locally to reduce repeated requests.
Handle errors gracefully
Check for partial errors in batch responses.
Next steps
API Reference
Complete endpoint documentation
Data dictionary
All available objects and fields
Sample code
Working code examples
Error handling
Handle errors gracefully