Skip to main content
Client supports three X API v2 auth modes:
  • Bearer Token (app-only): Public read, search, and streaming endpoints.
  • OAuth 2.0 PKCE (user context): Scoped user actions (creating posts, bookmarks, DMs, X Chat) with refresh tokens.
  • OAuth 1.0a (user context): HMAC-SHA1 request signing.
Get your app credentials from the X Developer Console.

Bearer Token

OAuth 2.0 with PKCE

Register a redirect URI (for example, http://localhost:8080/callback) on your app in the Developer Console, then run the PKCE flow with OAuth2PKCEAuth:

Refreshing tokens

OAuth 1.0a

OAuth 1.0a is disabled for newly created apps and is scheduled to be retired on January 31, 2027. Newly created apps must use OAuth 2.0 with PKCE or Bearer Token. Existing apps with OAuth 1.0a enabled can continue using it until January 31, 2027 — see Migrate from OAuth 1.0a to OAuth 2.0.
With existing access tokens:
Or run the full 3-legged flow:
See the Python samples repo for more examples.