# How to Automate X (Twitter) Analytics Reports using the API

- Tool: API Automations
- Difficulty: Intermediate
- Fix time: 30-60 minutes
- Compatibility: Basic tier ($200/month) or pay-per-use | OAuth 2.0 with PKCE required
- Last updated: May 2026

## TL;DR

Automate X (Twitter) analytics reports using GET /2/users/{id}/tweets with tweet.fields=public_metrics on the Twitter API v2. Requires OAuth 2.0 with offline.access scope for token refresh. Cost warning: reading your own tweets costs $0.001 per read on pay-per-use; Basic tier ($200/month) includes 15,000 reads/month. Note: follower/following counts were removed from self-serve tiers in April 2026.

## Best practices

- Include offline.access in your OAuth scopes — without it you cannot get a refresh token and users must re-authorize every 2 hours
- Track your monthly read consumption proactively — on pay-per-use, 100 tweets fetched daily costs ~$3/month, while Basic tier at $200/month includes 15,000 reads
- Store user_id persistently after the first lookup — /users/me costs a read each time and the ID never changes
- Use impression-based engagement rates now that follower counts are unavailable on self-serve tiers (removed April 2026)
- Always save historical report data locally — X API Basic tier only returns the last 7 days, so once the window passes, the data is gone
- Check x-rate-limit-remaining on every response and back off proactively when below 20% remaining
- Build token refresh into every API call function rather than as a separate step — token expiry can happen mid-run on long reports

## Frequently asked questions

### Is the X (Twitter) API free for analytics reports?

The Free tier is effectively unusable for analytics — it provides zero tweet reads. You need Basic ($200/month, 15,000 reads/month) or pay-per-use ($0.001/read for own tweets). For a weekly report fetching 100 tweets weekly, that is 400 reads/month on pay-per-use, costing about $0.40/month — well under the Basic tier cost.

### Why can't I get follower count data anymore?

X removed follower_count and following_count from the public_metrics response for all self-serve API tiers (Free, Basic, and Pro's lower access levels) in April 2026. This data is only available on the Enterprise tier ($42,000+/year). Use impression-based engagement rates instead — they are more accurate anyway since they reflect actual content reach.

### What happens when I hit the rate limit?

The API returns HTTP 429 with x-rate-limit-reset (Unix timestamp) and x-rate-limit-remaining (0) headers. Sleep until the reset time plus a 5-second buffer, then retry. For the monthly cap (15,000 reads on Basic), there is no retry — the cap resets on your billing cycle date.

### My access token expired and I got a 401 error. How do I refresh it?

POST to https://api.twitter.com/2/oauth2/token with grant_type=refresh_token and your current refresh_token. You will get a new access_token (and usually a new refresh_token). Critical: immediately replace your stored refresh_token with the new one — the old token is permanently invalidated and cannot be used again.

### Can I get analytics data for other users' tweets?

Only public_metrics (likes, retweets, replies, quotes) are available for other users' tweets. Non-public and organic metrics require the tweet author's OAuth token. Each other-user tweet read costs $0.005 on pay-per-use (vs $0.001 for your own tweets). Competitor analytics requires significant API budget.

### How far back can I fetch tweet history?

Basic tier: GET /2/users/{id}/tweets returns the 3,200 most recent tweets. You can use start_time to filter by date. Full archive search (all tweets ever) requires the Academic Research product or the Pro/Enterprise tiers. For your own tweet history, the 3,200 tweet cap is usually sufficient for analytics.

### Can RapidDev build a custom X analytics dashboard for my brand?

Yes. RapidDev has built 600+ integrations including social media analytics platforms. We can build production-grade X analytics automation with cost monitoring, multi-account support, and custom reporting. Book a free consultation at rapidevelopers.com.

---

Source: https://www.rapidevelopers.com/api-automations/how-to-automate-twitter-analytics-reports-using-the-api
© RapidDev — https://www.rapidevelopers.com/api-automations/how-to-automate-twitter-analytics-reports-using-the-api
