Skip to main content
This guide covers the key concepts you need to integrate the Post lookup endpoints into your application.

Authentication

All X API v2 endpoints require authentication. Choose the method that fits your use case:
MethodBest forCan access private metrics?
OAuth 2.0 App-OnlyServer-to-server, public dataNo
OAuth 2.0 Authorization Code with PKCEUser-facing appsYes (for authorized user’s Posts)
OAuth 1.0a User ContextLegacy integrationsYes (for authorized user’s Posts)

App-Only authentication

For public Post data, use a Bearer Token:
cURL
curl "https://api.x.com/2/tweets/1234567890" \
  -H "Authorization: Bearer $BEARER_TOKEN"

User Context authentication

To access private metrics, authenticate on behalf of the Post author:
The following fields require User Context authentication:
  • 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

Fields and expansions

The X API v2 returns minimal data by default. Use fields and expansions to request exactly what you need.

Default response

{
  "data": {
    "id": "1234567890",
    "text": "Hello world!",
    "edit_history_tweet_ids": ["1234567890"]
  }
}

Available fields

FieldDescription
created_atPost creation timestamp
author_idAuthor’s user ID
public_metricsLike, retweet, reply, quote counts
entitiesHashtags, mentions, URLs, cashtags
attachmentsMedia keys, poll IDs
conversation_idThread identifier
context_annotationsTopic/entity classifications
in_reply_to_user_idUser being replied to
langDetected language
sourcePosting client
possibly_sensitiveSensitive content flag
reply_settingsWho can reply
FieldDescription
username@handle
nameDisplay name
profile_image_urlAvatar URL
verifiedVerification status
descriptionBio
public_metricsFollower/following counts
created_atAccount creation date
FieldDescription
urlMedia URL
preview_image_urlThumbnail URL
typephoto, video, animated_gif
duration_msVideo duration
height, widthDimensions
alt_textAccessibility text

Example with fields

cURL
curl "https://api.x.com/2/tweets/1234567890?\
tweet.fields=created_at,public_metrics,entities&\
expansions=author_id,attachments.media_keys&\
user.fields=username,verified&\
media.fields=url,type" \
  -H "Authorization: Bearer $BEARER_TOKEN"

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_ids contains all versions (oldest first)
  • The endpoint always returns the most recent version

Example response

{
  "data": {
    "id": "1234567893",
    "text": "Hello world! (edited twice)",
    "edit_history_tweet_ids": [
      "1234567890",
      "1234567891",
      "1234567893"
    ]
  }
}
Posts retrieved after their 30-minute edit window represent the final version. For real-time use cases, be aware that recently-published Posts may still be edited.

Error handling

Common errors

StatusErrorSolution
400Invalid requestCheck parameter formatting
401UnauthorizedVerify authentication credentials
403ForbiddenCheck App permissions
404Not FoundPost deleted or doesn’t exist
429Too Many RequestsWait and retry (see rate limits)

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 errors array
{
  "data": [
    { "id": "1234567890", "text": "Available post" }
  ],
  "errors": [
    {
      "resource_id": "1234567891",
      "resource_type": "tweet",
      "title": "Not Found Error",
      "detail": "Could not find tweet with id: [1234567891]."
    }
  ]
}

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