Retrieving more than 150 Instagram comments

Instagram Api

Instagram Api Problem Overview


#The Problem# I would like to be able view all of the comments on any given piece of [Instagram][1] media, even if the media has over 150 comments. As of now, it is seemingly impossible to view more than the most recent 20 comments on a piece of media on the Instagram site and if one uses either the [Instagram API Console][2] or the [Instagram API Libraries][3], the most recent 150 comments are returned with no options for pagination or viewing addition comments.

#What I Have Tried# I first, of course, tried the documented [media comment query][4] in both the provided console and in my own environment. In both cases, a maximum of 150 comments were returned. Stumped, I began looking for more information online.

Having read over the [Instagram API Documentation][5] thoroughly, tested various endpoints in the [Instagram API Console][6], and read various StackOverflow questions in the Instagram tag and [Instagram API Google Group][7] questions on several Instagram topics, I wondered if there was a chance of something being undocumented that I could try.

The [user recent media endpoint][8] documentation includes parameters for max_id and max_timestamp that allow for paging through the most recent media for any given user by retrieving the media that comes before said max_id or max_timestamp. Since each comment comes with created_time and id attributes, I attempted to add the parameters for max_id and max_timestamp (both on their own and together) for various comment IDs and timestamps in an attempt to page through comments. None of my attempts worked.

I am now at a standstill unless someone has another suggestion.

#Specific Example# Using the [Instagram API Console][9], I took the following steps in attempt to get all of the comments for [this photo][10].

  1. Authenticated myself for an OAuth2 token
  2. Ran a user search query for coltonlhaynes to obtain the user id: 9610843
  3. Ran a user recent media query for user id: 9610843 to obtain the most recent media
  4. Gathered information about the most recent media (the above linked photo)
  • media id: 698057751201132903_9610843
  • comment count: 1375
  1. Ran a media comment query for media id: 698057751201132903_9610843 to obtain most recent comments
  2. Gathered information about the least recent comment
  • created time: 1397460230
  • comment id: 698269477955776593
  1. Ran a media comment query for media id: 698057751201132903_9610843 with the following additional query parameter strings in attempt to page through comments, but received the same results as step #6
  • ?max_timestamp=1397460230
  • ?max_id=698269477955776593
  • ?max_timestamp=1397460230&max_id=698269477955776593
  • ?max_id=698269477955776593&max_timestamp=1397460230

#Please Note# To my knowledge, there is no solution to this issue, but since the Instagram Development Team [has stated][11] that they will no longer be monitoring the Google Group and will be monitoring StackOverflow instead, I'm putting this here.

[1]: http://instagram.com "Instagram Site" [2]: http://instagram.com/developer/api-console/ "Instagram API Console" [3]: http://instagram.com/developer/libraries/ "Instagram API Libraries" [4]: http://instagram.com/developer/endpoints/comments/#get_media_comments "Instagram API: Get Media Comments Endpoint" [5]: http://instagram.com/developer/ "Instagram API Documentation" [6]: http://instagram.com/developer/api-console/ "Instagram API Console" [7]: https://groups.google.com/forum/#!forum/instagram-api-developers "Instagram API Google Group" [8]: http://instagram.com/developer/endpoints/users/#get_users_media_recent_with_client_id "Instagram API: User Recent Media Endpoint" [9]: http://instagram.com/developer/api-console/ "Instagram API Console" [10]: http://instagram.com/p/mv_9OFDTFn "Instagram Photo by user coltonlhaynes" [11]: http://instagram.com/developer/support/ "Instagram API Support"

Instagram Api Solutions


Solution 1 - Instagram Api

Ok, This is going to be a very "Hacky" solution, and I am not currently setup to do this myself (due to lack of ADSL at home) but I can provide a step by step guide of how I would approach this issue.

First of all you will need a tool called "Charles Web Debuging Proxy"

There is a tutorial on the site on how to enable "SSL debugging" in charles, (which will require you to install a new "root certificate" on your mobile device, to trick it into thinking that https transactions signed by charles are actually signed by instagram.com )

Now Set your mobile device to route all requests through said proxy ( which will have to be installed on your local wi-fi network.)

go to https://www.google.com and check that charles is logging both requests and responses.

Once this is all setup correctly then you can take a look at the API calls which the instagram app itself uses to generate said comment pages.

Solution 2 - Instagram Api

The generic answer here is "no, that's not possible via regular endpoints".

Instagram updated Rate Limits (after Nov 17, 2015). All rate limits on the Instagram Platform are controlled separately for each access token, and on a sliding 1-hour window. Live apps have higher rate limits than apps in Sandbox Mode.

Which state next limitations in global context:

> ### Global Rate Limits > > Global rate limits are applied inclusive of all API calls made by an > app per access token over the 1-hour sliding window, regardless of the > particular endpoint. Rate limits also apply to invalid or malformed > requests. >
> - Sandbox RATE LIMIT: 500 / hour > - Live RATE LIMIT: 5000 / hour

Plus separately limitations for comments endpoints:

> ### Endpoint-Specific Rate Limits > Endpoints used to publish (POST or DELETE) have rate limits that are applied on an per-endpoint basis. > Any calls made to these endpoints by your OAuth Client are also > counted towards the global rate limits noted above. > > - Sandbox /media/media-id/comments: 30 / hour > - Live /media/media-id/comments: 60 / hour

If your app exceeds any of these rate limits, you will receive a response with an HTTP response code of 429 (Too Many Requests).

As soon as Instagram Platform controls it on per access token basis, you might achieve a bigger limits using multi-threading with multiple access tokens. But it has caveats: 1. not everything could be paralleled from multiple access tokens, as context will be different. 2. It might contradict with Platform Policy and TOS

Solution 3 - Instagram Api

This isn't "hacky" at all.

As Instagram gives the link where you are able to get recieve all comments here: https://instagram.com/developer/endpoints/comments/

All you have to do is Looping over the link Instagram is giving you. I've done it like this. Im using the Api to do it this way.

  public function getUserMediaComments($id, $limit = 0) {
    return $this->_makeCall('media/'.$id.'/comments', true, array('count' => $limit));
  }

The $id is the media_id of the picture. If you foreach over that function with the picture id you'll recieve all comments.

It wasn't that hard when I found out about this way.

You could also do it like this while foreaching over it. :

$comments = json_decode(file_get_contents('https://api.instagram.com/v1/' . 'media/'. $image->id . '/comments?access_token='. $data->access_token));

It both returns you an array of the comments of the picture(s).

Solution 4 - Instagram Api

In accordance to what @Farside said, I don't believe that it is possible to do it by the books. However, you could do it by using Selenium and scraping all the comments in Python. You can use the InstaPy libary. They have Quick Start templates to make it really easy.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAllyView Question on Stackoverflow
Solution 1 - Instagram ApiDamian NikodemView Answer on Stackoverflow
Solution 2 - Instagram ApiFarsideView Answer on Stackoverflow
Solution 3 - Instagram ApiArmando van OeffelenView Answer on Stackoverflow
Solution 4 - Instagram ApiStefan DaceyView Answer on Stackoverflow