Mona Jalal
Mona Jalal

Reputation: 38145

Instagram API: getting the user id of all the users who have liked a post

How can I get all the users who have liked an image? I see that in page_info of a specific photo with 76 likes, there's u'end_cursor': None which I couldn't use in order to get the rest of the likes. Also as seen in this JSON only 10 of user's ID are shown.

                  u'page_info': {u'end_cursor': None,
                                 u'has_next_page': False,
                                 u'has_previous_page': False,
                                 u'start_cursor': None}},

http://pastebin.com/AZUQBvrF I had a similar problem with traversing to other pages of an Instagram user which I solved using the following code. However, I am unsure how to handle this when end_cursor=None? Please suggest solution and guidance.

 99             while data["user"]["media"]["page_info"]["has_next_page"]:
100                 end_cursors.append(data["user"]["media"]["page_info"]["end_cursor"])
101                 data = json.loads(requests.get('https://www.instagram.com/ducks_love_sun/?__a=1&max_id={}'.format(end_cursors[-1])).text)
102                 #pprint(data)
103                 
104                 for i in range(len(json_response["user"]["media"]["nodes"])):
105                     count = count + 1
106                     print json_response["user"]["media"]["nodes"][i]["likes"]["count"], count

In a single image we see this:

 u'likes': {u'count': 76,
                       u'nodes': [{u'user':

but there's only 10 nodes shown in the json!

Feel free to look at this for an example: https://www.instagram.com/p/BRG1WiEA1yM/?__a=1

I tried the followed but still get the content of 10 nodes:

pprint(img_response["media"]["likes"].items())

result is shown here: http://pastebin.com/7rPLqnUS

**UPDATE: as you see in this pastebin, the json of a photo with many comments has end_cursor and I can use that to traverse all of the comments:

http://pastebin.com/wbeZAt8y

While there's no cursor for likes seemingly!

Upvotes: 1

Views: 3831

Answers (1)

Tamim Ibrahim
Tamim Ibrahim

Reputation: 135

That reverse endpoint will not return more than 10 instagram photo liked user id.

So you can use Instagram official API endpoint to get all liked user id https://www.instagram.com/developer/endpoints/likes/#get_media_likes

Upvotes: 0

Related Questions