Reputation: 1
I am trying to use Instagram API to create a gallery with all user's instagram pictures. But I have just about 33 pictures in the gallery. Can you help me please? How can I fix this?
$response = file_get_contents('https://api.instagram.com/v1/users/' . $target . '/media/recent?access_token=' . $_SESSION['instagram_token'] . '&count=-1');
Upvotes: 0
Views: 18351
Reputation: 12657
The Instagram API imposes a silent, undocumented limit on how many results it returns. Even if you pass in a count
higher than 33
, it will only return, at most, 33 results.
I have written a hack in Javascript which eliminates this limit at the cost of making more API calls. At the moment, it only works if you query by user, but I can implement it so it works for queries by tag too, depending on my available time and demand.
Feel free to contribute by submitting pull requests! (You may want to translate what I did to PHP code so you can securely use the access token)
Upvotes: 0
Reputation: 12952
Each API call will return maximum of 20 photos, you have to use the pagination.url
in the API response to make another API call to get next 20 photos and so on.
https://api.instagram.com/v1/users/3/media/recent/?access_token=ACCESS-TOKEN
Upvotes: 0
Reputation: 3616
According to documentation you are using an endpoint which will return all recent media from the user. Thus it does not promise to return all images. Even though you specify a count, there is a maximum number of images returned.
However, you can use pagination; see the following question/answer for information:
Instagram API: How to get all user media?
I suppose you can read 20 per request, then find the lowest id of the result and use this as the max id of the next request.
Request 1 (no max_id)
Id 100
Id 99
..
Id 81
Request 2 (max_id=81)
Id 80
..
Id 61
Request 3 (max_id=61)
Id 60
..
Id 41
Then keep requesting until you do not get any more media returned
Upvotes: 1