twitterapi.io is an independent third-party service. Not affiliated with X Corp.

Blogmost liked tweet

Most-Liked Tweets — Build Your Own Leaderboard via API

By Michael Park4 min read

Searches for 'most liked tweet' typically land on listicle articles celebrating viral moments. The lists are accurate at publish time and increasingly wrong months later — a top-10 ranking shifts whenever a new high-engagement post lands. The dev angle to this query is a programmatic leaderboard: pull live data from the search API, sort by like count, render as a sortable table. Refresh on a cron and the leaderboard self-updates.

This guide walks the implementation in Python with cost math per provider, a worked example snapshot of the API response shape, and the aggregation pattern that turns raw API output into a ranked leaderboard. Pricing references are URL-cited.

01 — Section

The pattern — three primitives behind any leaderboard

1. Fetch — query /twitter/tweet/advanced_search with a min_faves:N floor that filters out low-engagement tweets server-side. N depends on the scope: min_faves:1000000 returns million-like tweets (the all-time-leaderboard pool); min_faves:100000 widens to last-month and emerging viral tweets.

2. Sort — group results by id (dedup), sort by public_metrics.like_count descending, take top N.

3. Cache + serve — write the sorted result to your warehouse or CDN cache with a captured-at timestamp. Refresh on a cron (daily for all-time, hourly for trending). The cache absorbs reader traffic so each pageview doesn't fire an API call.

02 — Section

Path 1 — twitterapi.io

twitterapi.io's /twitter/tweet/advanced_search accepts the full X advanced-search expression. Auth is X-API-Key header.

Pricing per twitterapi.io/pricing: $0.00015 per returned tweet.

python
import os, requests
from operator import itemgetter

HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
BASE = "https://api.twitterapi.io"

def most_liked_leaderboard(min_faves: int = 1_000_000, top_n: int = 20):
    tweets, cursor = [], None
    for _ in range(10):  # cap pages so a runaway query doesn't drain credit
        params = {"query": f"min_faves:{min_faves}"}
        if cursor: params["cursor"] = cursor
        r = requests.get(
            f"{BASE}/twitter/tweet/advanced_search",
            headers=HEADERS, params=params, timeout=15,
        )
        r.raise_for_status()
        resp = r.json()
        tweets.extend(resp.get("tweets", []))
        cursor = resp.get("next_cursor")
        if not cursor: break

    # Dedup + sort
    seen, out = set(), []
    for t in tweets:
        if t["id"] in seen: continue
        seen.add(t["id"])
        likes = t.get("public_metrics", {}).get("like_count", 0)
        out.append({
            "id": t["id"],
            "author": t.get("author", {}).get("userName", "unknown"),
            "text": (t.get("text") or "")[:120],
            "likes": likes,
            "retweets": t.get("public_metrics", {}).get("retweet_count", 0),
        })

    return sorted(out, key=itemgetter("likes"), reverse=True)[:top_n]

for i, t in enumerate(most_liked_leaderboard(1_000_000, 10), 1):
    print(f"{i}. @{t['author']} — {t['likes']:,} likes — {t['text'][:60]}")
03 — Section

Path 2 — X official

X's /2/tweets/search/recent accepts the same operators with min_faves: working as documented in docs.x.com/x-api/posts/search/integrate/build-a-query.

Pricing per docs.x.com/x-api/getting-started/pricing: $0.005 per post read.

python
# pip install tweepy
import tweepy

client = tweepy.Client(bearer_token="YOUR_X_BEARER")

def most_liked_x(min_faves: int = 1_000_000, top_n: int = 20):
    tweets = []
    for page in tweepy.Paginator(
        client.search_recent_tweets,
        query=f"min_faves:{min_faves} -is:retweet lang:en",
        tweet_fields=["public_metrics", "created_at", "author_id"],
        max_results=100, limit=10,
    ):
        tweets.extend(page.data or [])
    sorted_tweets = sorted(
        tweets,
        key=lambda t: t.public_metrics["like_count"],
        reverse=True,
    )
    return sorted_tweets[:top_n]

for t in most_liked_x(1_000_000):
    print(f"@{t.author_id}: {t.public_metrics['like_count']:,} likes")
04 — Section

Side-by-side — 2 API paths for the same leaderboard

Per-call cost shown below is derived from each provider's published pricing page.

Dimensiontwitterapi.ioX official
Per-tweet cost$0.00015 (twitterapi.io/pricing)$0.005 (docs.x.com)
Refresh cost (500 results)$0.075$2.50
Recent / archive searchfull archive includedrecent (7d) — full archive is enterprise
Cursor paginationyesyes
AuthX-API-Key headerbearer token
Best forleaderboard product, public sitealready on X official, low-volume

Two practical observations: (a) at $0.075/refresh, hourly leaderboard refresh costs ~$2/month — cheap enough to serve from your own infra; (b) twitterapi.io's full-archive access matters for the min_faves:1000000 all-time pool, which spans years.

05 — Section

Common static-list 'facts' to double-check live

Several tweets are widely cited as 'the most-liked tweet ever' across listicle sources — but the actual current top-10 shifts whenever a high-engagement post lands. Treat any unverified figure below as 'historical reference' and re-query the API for current state:

- Chadwick Boseman tribute (@chadwickboseman, 2020 — ~6.8M+ likes widely cited)

- Various Elon Musk / Donald Trump posts at the multi-million-like range

- High-engagement K-pop fan moments (BTS / Stray Kids / Twice context)

Running the API query above returns the current ranking sourced from live data. Pin the static reference numbers in your readme; rank from live API.

06 — Section

Leaderboard frontend — sortable table pattern

Recommended shape: a sortable HTML table with columns for rank, author, tweet excerpt, like count, retweet count, link-to-tweet. Sticky header for long scroll. Client-side sort by column header for filtering by retweets vs likes vs replies.

Update cadence: daily refresh for all-time leaderboard, hourly for trending. Lower SLA = lower API cost.

Storage: write each refresh to your warehouse or KV store; serve from cache. Don't fire an API call per page view — cache-bust per refresh tick instead.

07 — Section

Picking the path

Building a public leaderboard product? → twitterapi.io. Per-refresh cost makes it viable at any scale; full-archive access matters for all-time queries.

Already on X official? → either works at low refresh cadence. Cross 'most-liked' off the easy list once you start charging users for the leaderboard, then twitterapi.io's cost ratio matters.

Research / one-off list? → either works at low cost; pick by what's already configured.

python
# Practical example: nightly leaderboard refresh → JSONL artifact for your frontend.
import os, requests, json
from operator import itemgetter
from datetime import datetime, timezone

HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
BASE = "https://api.twitterapi.io"

def refresh_leaderboard(min_faves: int = 1_000_000, top_n: int = 50, out: str = "leaderboard.json"):
    tweets, cursor = [], None
    for _ in range(15):
        params = {"query": f"min_faves:{min_faves}"}
        if cursor: params["cursor"] = cursor
        r = requests.get(f"{BASE}/twitter/tweet/advanced_search", headers=HEADERS, params=params, timeout=15)
        r.raise_for_status()
        resp = r.json()
        tweets.extend(resp.get("tweets", []))
        cursor = resp.get("next_cursor")
        if not cursor: break

    seen, rows = set(), []
    for t in tweets:
        if t["id"] in seen: continue
        seen.add(t["id"])
        likes = t.get("public_metrics", {}).get("like_count", 0)
        rows.append({
            "rank": 0,  # filled below after sort
            "id": t["id"],
            "author": t.get("author", {}).get("userName", "unknown"),
            "text": (t.get("text") or "")[:200],
            "likes": likes,
            "retweets": t.get("public_metrics", {}).get("retweet_count", 0),
        })

    rows.sort(key=itemgetter("likes"), reverse=True)
    rows = rows[:top_n]
    for i, r in enumerate(rows, 1):
        r["rank"] = i

    snapshot = {
        "captured_at": datetime.now(timezone.utc).isoformat(),
        "min_faves_filter": min_faves,
        "rows": rows,
    }
    with open(out, "w") as f:
        json.dump(snapshot, f, indent=2)
    return snapshot

snap = refresh_leaderboard(min_faves=1_000_000, top_n=50)
print(f"top-{len(snap['rows'])} captured at {snap['captured_at']}")
for r in snap["rows"][:5]:
    print(f"  #{r['rank']} @{r['author']}: {r['likes']:,} likes")

# Cost math (derived from twitterapi.io/pricing):
#   500 tweets per refresh × $0.00015 = $0.075 per refresh
#   Daily refresh: $0.075 × 30 = $2.25/mo for a daily-updated leaderboard
#   Hourly refresh: $0.075 × 720 = $54/mo for an hourly leaderboard
# Pick cadence by how 'live' your readers expect — daily is enough for all-time.
08 — Questions

Questions readers ask

What is the most-liked tweet right now?

Rather than rely on listicle articles that go stale, query the API directly: /twitter/tweet/advanced_search?query=min_faves:1000000 returns the current pool of million-like-plus tweets, sortable by like_count. Re-running every day or hour gives the current top.

Why does my leaderboard sometimes return fewer than expected rows?

X's advanced-search backend de-duplicates and excludes some content types (replies under certain settings, withheld content, deleted tweets). If your min_faves floor is high and the resulting set is small, lower the floor or check the deletion-rate of your historical pool.

Can I build a 'most-liked tweets of this week / month / year' leaderboard?

Yes — add a date range to the operator: min_faves:100000 since:2026-01-01 until:2026-01-31 returns January's high-likes posts. Per twitterapi.io archive coverage, you can go back many years.

Should I cache results or hit the API per page view?

Cache per refresh tick (daily/hourly), serve cached rows from your CDN or KV store. Per-page-view API calls don't scale economically — even at twitterapi.io's $0.00015/tweet, 10K page views × 50 tweets/view = $7.50/day in raw cost that's avoidable with a 50-row cache.

What about engagement-bait / spam-like tweets?

High-likes tweets sometimes include amplification campaigns or coordinated likes. For an analytics product, filter -is:retweet plus require a minimum retweet_count (real reach tracks both) to surface organically-engaging content rather than pure-like amplification.

Where does the 'Chadwick Boseman tribute is the most-liked tweet ever' figure come from?

Widely cited across mainstream news outlets at multiple points; not an authoritative running figure. Use it as 'historical reference' in your context line, but rank from live API. The current top can shift with any new high-engagement post.

09 — Further reading

Continue

Sources & further reading
More from this series
Build it

Stop reading. Start building.

Starter credits cover real testing on real data. Google sign-in, no card, no application queue.

Get an API key
    Most-Liked Tweets — Build Your Own API | TwitterAPI.io