Hank
Hank

Reputation: 731

How to get ALL likes for a given media-id

I am trying to iterate over the user ID of each like for a given {media_id}

https://api.instagram.com/v1/media/{media-id}/likes?access_token=ACCESS-TOKEN

is returning something like this (a data array of approx 300 likes)

{
    "data": [{
        "username": "jack",
        "first_name": "Jack",
        "last_name": "Dorsey",
        "type": "user",
        "id": "66"
    },
    {
        "username": "sammyjack",
        "first_name": "Sammy",
        "last_name": "Jack",
        "type": "user",
        "id": "29648"
    }]
}

The problem is that it does not return ALL the likes, or any pagination feature.

Is there any workaround to get ALL likes for a given {media_ID}?

Upvotes: 5

Views: 7320

Answers (2)

Cameron Cobb
Cameron Cobb

Reputation: 113

Check this Python library out.

Then you can use this sample code I made; however, It will only get 1000 of the most recent likes.

from InstagramAPI import InstagramAPI

likes_list = []

def get_likes_list(username):

    API.searchUsername(username) #Gets most recent post from user
    info = API.LastJson
    username_id = info['user']['pk']
    user_posts = API.getUserFeed(username_id)
    info = API.LastJson
    media_id = info['items'][0]['id']

    API.getMediaLikers(media_id)
    f = API.LastJson['users']
    for x in f:
        likes_list.append(x['username'])

get_likes_list("tailopez")
print(likes_list)

Upvotes: 3

stacky
stacky

Reputation: 236

You're using the correct API endpoint to get media likes, however this endpoint has a limitation. It only returns a maximum of 100-120 likes per media with no pagination.

Unfortunately there is no workaround!

The same limitation applies for the comments endpoint.

Upvotes: 8

Related Questions