For AI

Answers

How do I get Instagram posts for a hashtag through an API?

Short answer

Call Instagram hashtag posts with the tag's name, without the #: each page returns about 10 public posts with caption, author, likes, comments and time posted, for $0.004. There is no business account, App Review or weekly hashtag limit, but you get a sample of the tag rather than every post, and not in time order. Five pages for each of 20 hashtags cost $0.40.

A camping-gear brand wants to see what people post under #vanlife, #overlanding and a dozen smaller tags each week, to spot photos worth licensing and creators worth contacting. Instagram's own route is Hashtag Search in the Graph API. It needs an Instagram Business or Creator account connected to your app, and App Review for the Instagram Public Content Access feature. Each account can query 30 unique hashtags in any rolling 7 days. The recent_media edge only returns posts from the last 24 hours, and you cannot request the username of the accounts that posted them. That last rule is why people asking for "all posts for a hashtag, with who posted them" keep hitting a wall.

Instagram hashtag posts takes the tag as id and returns each post with its author.

Steps

  1. List the tags. Mix the big generic tag with the specific ones your buyers use. The small tags are often more useful than the big one.
  2. Page through each tag with cursor, a few pages per tag.
  3. Merge and rank. One post often carries several of your tags, so remove duplicates by id, then sort by metrics.likes and metrics.comments.
  4. Go deeper on the keepers. Instagram post detail ($0.004) adds plays for reels, every image of a carousel and the other authors of a collab post. For a reel, Instagram reel transcript returns what is said in it ($0.004, videos up to two minutes).

A weekly pull

import csv, os, requests

API = "https://api.okdata.online"
H = {"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"}
TAGS = ["vanlife", "overlanding", "rooftoptent", "campervan"]

def tag_posts(tag, max_pages=5):
    cursor = None
    for _ in range(max_pages):
        params = {"id": tag, **({"cursor": cursor} if cursor else {})}
        body = requests.get(API + "/v1/instagram/hashtags/posts/list", headers=H, params=params, timeout=60).json()
        if body["code"] != "ok":
            raise RuntimeError(f"{body['code']}: {body['message']}")
        yield from body["data"]["items"]
        if not body["page"]["has_more"]:
            return
        cursor = body["page"]["next_cursor"]

posts = {}
for tag in TAGS:
    for p in tag_posts(tag):
        posts.setdefault(p["id"], {**p, "tags": set()})["tags"].add(tag)

score = lambda p: (p["metrics"]["likes"] or 0) + (p["metrics"]["comments"] or 0)
with open("hashtag-posts.csv", "w", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    w.writerow(["url", "author", "likes", "comments", "published_at", "tags", "caption"])
    for p in sorted(posts.values(), key=score, reverse=True):
        w.writerow([p["url"], p["author"]["username"], p["metrics"]["likes"], p["metrics"]["comments"],
                    p["published_at"], " ".join(sorted(p["tags"])), p["text"][:200]])

Cost

Job Calls Cost
One tag, 5 pages 5 $0.02
20 tags, 5 pages each 100 $0.40
The same every week for a month 400 $1.60
Detail on the 50 best posts 50 $0.20

A list call is charged even when a page comes back empty or fails at the data source; only calls refused before that, such as bad parameters, are free.

Limits

  • Posts come in the order search engines found them. You get a sample of the tag, not its full history, and you cannot ask for everything posted in the last 24 hours.
  • Paging ends after a limited number of pages per tag. To see more, add related tags rather than paging deeper.
  • Now and then a page comes back without author names or counts, and meta.unavailable lists the fields left empty. Fetch those posts with post detail if you need them.
  • Stories are not included, and neither are posts from private accounts.

When the Graph API is the better choice

If you already run an approved business app and need the newest posts under your own campaign tag within hours, recent_media returns up to 50 posts a page from the last 24 hours, and top_media returns the most popular ones. Thirty tags a week is enough for one branded campaign. For research across many tags, or without a business account, the sample here is simpler to get. The content research page has more on this job.

Sources

Where people asked this (read 2026-11-15)

Updated

Connect once, then just ask.

Every new key comes with $0.10 to try it. One sentence connects your agent.

Start free
Connect your AI

Paste this into your agent

Read https://okdata.online/agents.md and set up okdata for me; my key is in the OKDATA_API_KEY environment variable.

Claude Code, Cursor, Codex and other agents that can open a link set themselves up from it.

MCP serverhttps://api.okdata.online/mcp