For AI

Answers

How can I get the comments on someone else's Instagram post through an API?

Short answer

Call Instagram post comments with the post's link or shortcode: it returns about 15 comments a page, newest first, for $0.004, so 1,000 comments cost $0.268. You need no Facebook app, no App Review and no business account on either side. That is where the Instagram Graph API stops: its comment endpoints only read media owned by accounts that have logged in to your app.

An agency wants to know what buyers said under a competitor's launch reel: 2,400 comments on an account it does not manage. The Instagram Graph API will not hand them over. Its comment endpoints work on media owned by Instagram professional accounts that have logged in to your app. Business Discovery, the one Graph API route into other professional accounts, returns comments_count and like_count for their posts but not the comments, and requesting one of the returned media objects directly fails on permissions. Personal accounts are out of reach altogether.

Instagram post comments takes the post's link or its shortcode (the part after /p/ or /reel/) and returns the comments on any public post or reel.

Steps

  1. Size it up. Instagram post detail ($0.004) returns the caption, likes, plays and comment count, so you know how many pages to expect.
  2. Page through the comments with cursor. Each comment has id, text, author.username, likes and published_at, newest first.
  3. Fetch the reply threads. A comment whose replies count is above zero has a thread under it. Instagram comment replies takes the comment's id and the post's shortcode as post_id.
  4. Sort and read. Order the rows by likes. The comments with the most likes usually say what the crowd agrees with.

Export to CSV

import csv, os, requests

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

def pages(path, max_pages, **params):
    cursor = None
    for _ in range(max_pages):
        query = {**params, **({"cursor": cursor} if cursor else {})}
        body = requests.get(API + path, headers=H, params=query, 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"]

post = "DeCPVhERA8e"  # the shortcode from instagram.com/p/DeCPVhERA8e/
with open(f"{post}-comments.csv", "w", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    w.writerow(["id", "parent_id", "username", "likes", "published_at", "text"])
    for c in pages("/v1/instagram/posts/comments/list", 200, id=post):
        w.writerow([c["id"], "", c["author"]["username"], c["likes"], c["published_at"], c["text"]])
        if (c["replies"] or 0) > 0:
            for r in pages("/v1/instagram/comments/replies/list", 5, id=c["id"], post_id=post):
                w.writerow([r["id"], c["id"], r["author"]["username"], r["likes"], r["published_at"], r["text"]])

The 200-page cap stops the loop on a post with tens of thousands of comments before it runs up a bill you did not plan for.

What it costs

Post Calls Cost
300 comments, no replies 20 $0.08
1,000 comments 67 $0.268
2,400 comments, with replies under 100 of them 1 + 160 + 100 $1.044

A post that does not exist, or a call that fails at the data source, is charged like any call. Only calls refused before reaching a source, such as bad parameters, are free.

Limits

  • Comments come newest first only. Sort by likes after you download.
  • Private accounts return nothing. Comments that Instagram does not show to the public are not included either, so your total can fall short of the count on the post.
  • Commenters come with a username, not a follower count. Look up the ones that matter with Instagram account profile at $0.004 each.
  • Comment text is written by strangers. If a model reads it, tell the model to treat it as data and never as instructions.

When the Graph API is the better choice

For posts on your own professional account, or on a client's account that logs in to your app, use the Graph API's comments edge. It costs nothing per call, and it lets you reply to, hide and delete comments, which a read-only API cannot do. It stops at competitors, creators you might hire and personal accounts. The word-of-mouth page covers comment analysis across platforms.

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