Setting up an X app for OAuth 2.0
This guide is part of the Publicus connection catalog. Once you have the credentials, connect the service and Publicus stores them for you.
Distilled from X’s own documentation: Getting Access, Apps, OAuth 2.0 Authorization Code Flow with PKCE, How to connect using OAuth 2.0, Migrating OAuth 1.0a user tokens to OAuth 2.0 and X API pay-per-usage pricing. Retrieved 2026-10-25.
OAuth 2.0 lets your X app act for an X user: post, read their timeline, send Direct Messages, and so on, each limited by the scopes the user grants. You get a Client ID and a Client Secret from an app in the X Developer Console.
The X API is paid. It is billed pay-per-usage, with no subscription: you buy credits in the Developer Console, and each request spends them, priced per resource read or per write (the current rates are in the console and on the pricing page). Requests are refused once the balance hits zero or a spending limit you set is reached. Pay-per-usage is capped at 3 million Post reads per monthly billing cycle; beyond that X offers an Enterprise plan. Because the bill goes to the account that owns the app, use an app on your own developer account.
- Go to the X Developer Console and sign in with your X account. The first time, accept the Developer Agreement and Policy and complete your profile with how you will use the API.
- Buy credits. Without a balance every request is refused. Optionally turn on Auto-recharge and set a Spending limit per billing cycle.
- Create an app (New App or Create App) and give it a name, a description and a use case.
- In the app’s settings, set up OAuth 2.0:
- choose the type of app Web App or Automated App / Bot. Both are confidential clients and come with a Client Secret. Native App and Single Page App are public clients with no secret, and do not fit a server-side connection;
- add the Callback URI / Redirect URL exactly as the connect form shows it, trailing slash included. An app takes at most 10 callback URLs, and
https://is expected in production; - fill in the Website URL.
- Under Keys and tokens, copy the OAuth 2.0 Client ID and the Client Secret. Credentials are shown once only, and regenerating them invalidates the old ones.
- Store both in a vault.
Operational notes:
- Users authorize at
https://x.com/i/oauth2/authorize. PKCE is part of every request, and the authorization code expires 30 seconds after it is issued, so it is exchanged straight away athttps://api.x.com/2/oauth2/tokenwith anAuthorization: Basicheader built from the Client ID and secret. - Ask for
offline.accessor no refresh token is issued. Access tokens last 2 hours. Refresh tokens last about 6 months and are single-use: each refresh returns a new one, which must be saved before the next refresh. - Nearly every user-context endpoint needs
tweet.readandusers.readon top of its own scope. For example, posting needstweet.writeas well, and sending a Direct Message needsdm.write. - A user can remove the app’s access at any time from their connected apps settings.
Connect it to Publicus
Section titled “Connect it to Publicus”Open Connections under Credentials, choose X, and pick X OAuth 2.0 (authorization code with PKCE). Publicus asks for exactly the fields listed above and keeps them in your workspace’s secret storage.
See also: X in the catalog.
This guide is maintained by Publicus and published under CC BY 4.0.