Instagram API media/comments接口未返回最新评论,如何获取全部或降序评论?
Great question—this is a super common gotcha with the Instagram Comments API that tripped me up when I was building a user engagement tracking tool a while back! Let’s break down your two questions clearly:
Can You Fetch All Comments for a Media Item?
Absolutely—you just need to use the API’s built-in pagination system. The default 30-comment limit is intentional to keep response sizes manageable, but the API gives you everything you need to pull the rest:
- When you make your first request to the comments endpoint, look for a
paginationobject in the response. It’ll either have a ready-to-usenext_urlor anext_max_idparameter. - For each follow-up request, append the
max_idparameter (using the value fromnext_max_id) to your call. This tells the API to return comments older than the last one from your previous batch. - Keep repeating this until the
paginationobject disappears from the response—once that happens, you’ve grabbed all available comments.
Here’s a quick pseudocode example to illustrate the flow:
all_comments = [] current_request_url = "https://api.instagram.com/v1/media/{media-id}/comments?access_token={your-token}" while current_request_url: api_response = make_api_request(current_request_url) all_comments.extend(api_response["data"]) # Check if there's more to fetch if "pagination" in api_response and "next_url" in api_response["pagination"]: current_request_url = api_response["pagination"]["next_url"] else: current_request_url = None
Can You Get Comments Sorted by created_time Descending?
Even better—this is the default behavior of the API! The confusion here probably comes from the 30-comment limit: you’re only seeing the first 30 newest comments initially, but each pagination call will return the next set of older comments (still ordered from newest to oldest within their batch).
If you ever need to flip to oldest-first order, you can just sort the full list of collected comments locally using the created_time field once you’ve fetched everything.
Quick Heads-Up
- Don’t forget about Instagram’s rate limits—too many rapid pagination requests can get your access token temporarily restricted. Space out your calls if you’re dealing with media items with tons of comments.
- Make sure your access token has the right permissions:
public_contentfor public media, or the appropriate scopes if you’re accessing private accounts you have authorization for.
内容的提问来源于stack exchange,提问作者Vijay K

