Twitter (X) Follower Count — API Tutorial
Follower count is the single most-queried field on any Twitter (X) account — the basic 'how big is this account' number that fuels dashboards, growth tracking, competitive analysis, and journalism. This tutorial walks the two API paths with runnable code + honest cost math.
Pricing references URL-cited to each provider.
The simplest call — one endpoint, one field
Both providers return follower count in a profile-lookup endpoint. Same field name (followers_count), same JSON shape at the level relevant to the query. Difference is per-call cost + auth.
For high-frequency polling (daily or hourly across many accounts), the per-call cost multiplied by volume decides which path fits.
Path 1 — twitterapi.io
Auth via X-API-Key header. Signup is email-based; no X account required.
Pricing per twitterapi.io/pricing: $0.00018 per lookup.
import os, requests
HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
BASE = "https://api.twitterapi.io"
def follower_count(handle: str) -> int:
r = requests.get(
f"{BASE}/twitter/user/info",
headers=HEADERS, params={"userName": handle}, timeout=10,
)
r.raise_for_status()
return r.json().get("followers_count", 0)
for h in ["nasa", "github", "vercel"]:
print(f" @{h}: {follower_count(h):,} followers")Path 2 — X official
Auth via bearer token from X Developer Console. Requires X account + Developer Console onboarding.
Pricing per docs.x.com/x-api/getting-started/pricing: $0.010 per profile lookup.
# pip install tweepy
import tweepy
client = tweepy.Client(bearer_token="YOUR_X_BEARER")
def follower_count_x(handle: str) -> int:
user = client.get_user(username=handle, user_fields=["public_metrics"])
return user.data.public_metrics.get("followers_count", 0)
for h in ["nasa", "github", "vercel"]:
print(f" @{h}: {follower_count_x(h):,}")Side-by-side — 2 paths for follower count
Per-call cost ratio: ~55×. At meaningful polling volumes the delta compounds fast.
Common polling workflows — cost math
Single account, daily check: 30 calls/month. twitterapi.io: $0.0054. X official: $0.30. Ratio: 55×.
Competitive dashboard, 20 accounts, daily: 600 calls/month. twitterapi.io: $0.11. X official: $6.00.
Growth tracking, 100 accounts, hourly: 72,000 calls/month. twitterapi.io: $12.96. X official: $720. Ratio: 55×.
Journalism / research, 1000 accounts, daily: 30,000 calls/month. twitterapi.io: $5.40. X official: $300.
The ratio holds at any volume. Choice depends on setup convenience + existing infrastructure.
Storing follower count over time
Follower count as a scalar isn't useful for growth analysis — you need time series. Store per-lookup as (handle, timestamp, followers_count) rows in your warehouse.
SQL for querying growth-rate: SELECT handle, MAX(followers_count) - MIN(followers_count) AS growth FROM followers WHERE captured_at BETWEEN X AND Y GROUP BY handle.
For dashboards, render the time-series as a line chart. Anomalies (sudden drops = likely purge / suspension; sudden spikes = viral moment) become visible at a glance.
Follower count vs 'active followers'
Follower count is what accounts follow the target. It's not the same as 'active audience'. Some followers are bots or dormant.
For active-audience estimation, combine follower count with engagement metrics (avg likes / retweets per post from /twitter/user/last_tweets). Engagement-per-1K-followers is a health signal even when raw follower count is stable.
Reference: /blog/twitter-engagement-rate-calculator-api for the engagement-rate calculation pattern.
# Practical example: daily follower-count snapshot for a watchlist → JSONL time-series.
import os, requests, json
from datetime import datetime, timezone
from pathlib import Path
HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
BASE = "https://api.twitterapi.io"
WATCHLIST = [
"nasa", "github", "vercel", "anthropic", "openai",
"elonmusk", "realDonaldTrump", "BarackObama",
]
def snapshot(out_path: str = "followers.jsonl"):
Path(out_path).parent.mkdir(exist_ok=True)
now = datetime.now(timezone.utc).isoformat()
with open(out_path, "a") as f:
for h in WATCHLIST:
r = requests.get(f"{BASE}/twitter/user/info", headers=HEADERS, params={"userName": h}, timeout=10)
if r.status_code == 404: continue
r.raise_for_status()
f.write(json.dumps({
"captured_at": now,
"handle": h,
"followers_count": r.json().get("followers_count", 0),
}) + "\n")
snapshot()
# Cost per twitterapi.io/pricing:
# 8 lookups × $0.00018 = $0.00144 per daily snapshot
# Daily × 30 = ~$0.043/month for the full watchlist time-series
# Same via X official: ~$2.40/month (55x)Questions readers ask
How current is the follower count returned?
Real-time at query. Both providers reflect the current state per their indexing latency (usually seconds). Follower changes propagate quickly.
Can I get historical follower counts?
Neither API returns historical follower series directly — you have to build the time series by snapshotting periodically. For growth analysis, snapshot daily + query your own store.
What about follower count for accounts I don't follow?
All follower counts on public accounts are visible via the API. No follow relationship required. Only fully-private accounts are gated.
Do bot / spam followers count?
Yes, the count is total-followers including any bots. X occasionally does platform-wide bot purges that drop counts across affected accounts. Track deltas over time — you'll see the purge as a step function.
How do I detect an account being suspended or deleted?
API returns 404 on deleted / suspended handles. Handle that in your snapshot script (skip and log) so your time-series has gaps rather than errors.
Rate limits?
twitterapi.io: per-API-key throughput lands in the thousands of calls/hour on standard tier. X official: tier-based, tighter. For polling at your typical dashboard cadence (hundreds of calls/day) neither is a constraint.
Continue
- Twitter (X) API — cluster hub
- Twitter (X) counter API guide
- Twitter (X) follower tracking API guide
- Twitter (X) engagement rate calculator API
- twitterapi.io pricing
Stop reading. Start building.
Starter credits cover real testing on real data. Google sign-in, no card, no application queue.
Get an API key