Twitter uses GraphQL (Graph Query Language) for its internal API. Instead of traditional REST endpoints like /api/users/123, Twitter uses GraphQL operations with operation hashes (also called query IDs).
https://x.com/i/api/graphql/{OPERATION_HASH}/{OPERATION_NAME}?variables={JSON}
Example:
https://x.com/i/api/graphql/1VOOyvKkiI3FMmkeDNxM9A/UserByScreenName?variables={"screen_name":"elonmusk"}
-
Operation Hash (
1VOOyvKkiI3FMmkeDNxM9A): A unique identifier for the GraphQL query- Twitter changes these frequently (sometimes daily/weekly)
- This is why your code might stop working suddenly
-
Operation Name (
UserByScreenName): The name of the GraphQL operation- Examples:
CreateTweet,Followers,UserByScreenName,TweetDetail
- Examples:
-
Variables: JSON-encoded parameters for the query
- Open Twitter/X in your browser (logged in)
- Open Developer Tools (F12 or Right-click → Inspect)
- Go to Network tab
- Filter by "graphql" or "XHR"
- Perform the action you want to replicate:
- View a profile → Look for
UserByScreenName - View followers → Look for
Followers - Post a tweet → Look for
CreateTweet - View a tweet → Look for
TweetDetail
- View a profile → Look for
- Click on the request → Check the URL in the "Headers" or "Request" tab
- Extract the hash from the URL:
https://x.com/i/api/graphql/1VOOyvKkiI3FMmkeDNxM9A/UserByScreenName ^^^^^^^^^^^^^^^^^^^^ This is the hash!
- Open Twitter/X in browser
- Open Developer Tools → Console tab
- Run this JavaScript to intercept GraphQL requests:
// Intercept fetch requests
const originalFetch = window.fetch;
window.fetch = function(...args) {
const url = args[0];
if (url && url.includes('/graphql/')) {
console.log('GraphQL Request:', url);
// Extract hash: /graphql/{HASH}/{OPERATION}
const match = url.match(/\/graphql\/([^\/]+)\/([^?]+)/);
if (match) {
console.log('Hash:', match[1]);
console.log('Operation:', match[2]);
}
}
return originalFetch.apply(this, args);
};- Burp Suite: Intercept and log all requests
- Charles Proxy: Monitor HTTP/HTTPS traffic
- mitmproxy: Command-line tool for intercepting requests
| Operation Name | Purpose | Current Hash (Example) |
|---|---|---|
UserByScreenName |
Get user info by username | 1VOOyvKkiI3FMmkeDNxM9A |
CreateTweet |
Post a new tweet | f4NGXqNlXoGYCWploMNtlQ |
Followers |
Get user's followers | - (uses - as hash) |
Following |
Get user's following | - (uses - as hash) |
TweetDetail |
Get tweet details | Varies |
UserTweets |
Get user's tweets | Varies |
Note: The hash - means Twitter uses a different method (often the operation name directly).
Twitter changes GraphQL hashes to:
- Prevent scraping/automation
- Update API versions
- Add new features
- Fix security issues
Frequency: Can change daily, weekly, or monthly. There's no fixed schedule.
const graphqlHashes = [
'1VOOyvKkiI3FMmkeDNxM9A', // Current
'G3KGOASz96M-Qu0nwmGXNg', // Previous
'OLD_HASH_HERE' // Older fallback
];
for (const hash of graphqlHashes) {
try {
const response = await makeRequest(`.../graphql/${hash}/...`);
if (response.ok) break;
} catch (e) {
continue; // Try next hash
}
}Some operations work with - as the hash:
const url = `https://x.com/i/api/graphql/-/Followers?variables=...`;Periodically check Twitter's network requests to update hashes automatically.
- Visit any Twitter profile:
https://twitter.com/username - Check Network tab for request containing
UserByScreenName - Extract hash from URL
- Visit a profile's followers page:
https://twitter.com/username/followers - Check Network tab for request containing
Followers - Extract hash (often uses
-)
- Compose a tweet (don't post it)
- Check Network tab for
CreateTweetrequest - Extract hash from URL
- Open any tweet
- Check Network tab for
TweetDetailor similar - Extract hash
- Go to
https://twitter.com/elonmusk - Open DevTools → Network tab
- Filter:
graphqlor search forUserByScreenName - Find request like:
GET https://x.com/i/api/graphql/1VOOyvKkiI3FMmkeDNxM9A/UserByScreenName?variables=... - Copy the hash:
1VOOyvKkiI3FMmkeDNxM9A
- Hash is outdated → Find new hash using Method 1 above
- Authentication issue → Check auth_token and ct0
- Bot detection → Add delays, use proxies
- Too many requests → Add delays between requests
- Twitter API Reverse Engineering Tools: Search GitHub for "twitter graphql hash"
- Browser Extensions: Some extensions can log GraphQL requests automatically
- Scripts: Write a script to monitor and log all GraphQL requests