Answers

How do I get the view count of any tweet through an API?

Short answer

Send the post's link or ID to X post detail: it returns views, likes, replies, reposts and bookmarks for any public post, yours or not, for $0.001 a post. Checking 50 campaign posts once a day for two weeks is 700 calls, $0.70.

An agency pays 10 creators to post about a launch and has to report views per post every day for two weeks. The posts belong to the creators, so the agency cannot read them through its own analytics. X post detail takes a post's link or ID and returns the public numbers X shows under the post. That works for any public post.

What comes back

  • metrics.views: the view count X displays
  • metrics.likes, metrics.reposts, metrics.comments (replies) and metrics.favorites (bookmarks)
  • ext.quotes (quote posts) when you add view=full
  • text, published_at, lang, media in images, and the author with follower count

metrics.shares is always null, because X does not show a share count, and the response says so in meta.unavailable.

Daily tracking

import csv, datetime, os, requests

API = "https://api.okdata.online/v1"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}

links = [line.strip() for line in open("campaign-posts.txt") if line.strip()]
today = datetime.date.today().isoformat()

with open("views.csv", "a", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    for link in links:
        body = requests.get(f"{API}/x/posts/get", headers=H, params={"url": link}, timeout=60).json()
        if body["code"] != "ok":
            w.writerow([today, link, body["code"]])  # not_found: deleted or protected, not charged
            continue
        m = body["data"]["item"]["metrics"]
        w.writerow([today, link, m["views"], m["likes"], m["reposts"], m["comments"], m["favorites"]])

Links can be x.com or twitter.com, including mobile links. Run the script once a day and the CSV turns into a growth curve per post.

Cost

Job Calls Cost
One post 1 $0.001
50 posts, once 50 $0.05
50 posts, daily for 14 days 700 $0.70

If the posts share a hashtag or mention, one X post search page ($0.006) returns about 20 posts with the same metrics, which is cheaper than fetching them one by one.

Gotchas

  • Posts from before X began showing view counts in late 2022 have no views, so views is null.
  • Deleted posts and protected accounts return not_found, which is not charged.
  • The numbers are what X shows the public at that moment. Impressions broken down by source, link clicks and profile visits are private analytics, visible only to the author.

The official alternative

X's own API includes impression_count in a post's public metrics, at $0.005 per post read under pay-per-use. That is a good fit if you already run on the X API. The author's private metrics, such as link clicks, need the author's own login on either route. For a wider campaign view, see the competitor monitoring guide.

Updated