Getting started with the X API
Get an API key and make your first authenticated request in about ten minutes.
Create a developer account
Sign in at the X Developer Platform and create a Project and an App inside it. The App is what holds your keys. Note three values: the API Key, API Secret, and a Bearer Token for app-only requests.
Keep secrets out of client-side code. A Bearer token in a public web app can be scraped and abused, so proxy it through a small backend.
Your first request
App-only requests can read public data without a user logging in. Here is a public user lookup with plain fetch:
const res = await fetch("https://api.x.com/2/users/by/username/jack", {
headers: { "Authorization": `Bearer ${BEARER_TOKEN}` }
});
const data = await res.json();
console.log(data); // { data: { id, name, username } }
What’s next
Reading public data is the easy half. To post, like, or read a user’s own timeline you need user-context auth (OAuth 2.0), which is the next chapter.
Frequently asked questions
Do I need a paid plan to start?
No. The free tier is enough to get credentials and make app-only read requests while you learn.
What is a Bearer token?
An app-only credential that lets you read public data without a user logging in. Keep it server-side, since a token in client code can be scraped.