You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Instagram按短代码获取帖子评论异常及完整请求咨询

关于Instagram GraphQL评论接口返回不完整的问题

Hey there, let's tackle this issue step by step. First off, this is not an Instagram bug—it's actually how their GraphQL API handles large comment sets via pagination, plus some common pitfalls with how you're structuring your requests.

Why the comment count doesn't match the list

Instagram intentionally limits the number of comments returned in a single API call, even if you set a high first value like 4500. There's a hard cap on how many comments you can fetch per request (usually around 100-200, though this can vary), so your initial request only gets a chunk of the total comments, not all of them. The "total comments" field in the response reflects the full count, but you need to paginate through subsequent requests to collect everything.

What's wrong with your current requests

Your second request has a malformed parameter structure. The after cursor shouldn't be a top-level URL parameter—it needs to be included inside the variables JSON object, just like shortcode and first. Instagram's GraphQL API expects all pagination-related parameters to be part of the variables payload, not appended directly to the URL.

Correct way to fetch the full comment list

Here's a step-by-step approach to get every comment:

  1. Initial request
    Start with a valid initial query to get the first batch of comments, along with pagination metadata:

    https://www.instagram.com/graphql/query/?query_id=17852405266163336&variables={"shortcode":"BemdtV0gLAL","first":100}
    

    (Note: Using first:100 is more reliable than 4500, since Instagram will cap it anyway.)

    In the response, look for the page_info object under data.shortcode_media.edge_media_to_parent_comment:

    • end_cursor: This is the token you'll use to fetch the next page of comments
    • has_next_page: A boolean that tells you if there are more comments to fetch
  2. Paginate through remaining comments
    While has_next_page is true, make subsequent requests by adding the end_cursor to your variables:

    https://www.instagram.com/graphql/query/?query_id=17852405266163336&variables={"shortcode":"BemdtV0gLAL","first":100,"after":"[INSERT_END_CURSOR_HERE]"}
    

    Replace [INSERT_END_CURSOR_HERE] with the end_cursor value from the previous response. Repeat this until has_next_page becomes false.

  3. Combine all results
    Collect the edges array from each response and merge them into a single list—this will give you the full set of comments that matches the total count.

Important notes

  • Query ID changes: Instagram regularly updates query_id values, so if your current one stops working, you'll need to find the latest valid ID (you can get this by inspecting network traffic when loading comments on Instagram's web interface).
  • Rate limiting: Be careful not to send too many requests too quickly—Instagram will block your IP if you hit their rate limits. Add small delays between pagination requests.
  • Hidden comments: In some cases, the total count might include comments that are filtered (e.g., spam, restricted content) and won't be returned in the API response. If you've paginated until has_next_page is false and still don't match the total, this could be the reason.

内容的提问来源于stack exchange,提问作者Alexey Gordienko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:36:52