Answer the question
In order to leave comments, you need to log in
PHP Instagram API: how to bypass the limit in the number of returned images?
Good day everyone! :D
I'm struggling with the Instagram API to bypass their limit when displaying images from my user's profile. By default, for some reason, this is the number 33. Why is it so - I didn’t find it in the docks ...
Here is a simple function to get these 33 images (I use saving the received response in a JSON file with subsequent parsing so as not to load traffic ):
function get_instagram($user_id = <MY_USER_ID>, $scope = 'public_content', $count = 100, $width = 190, $height = 190)
{
$url = 'https://api.instagram.com/v1/users/' . $user_id . '/media/recent/?access_token=<MY_ACCESS_TOKEN>&count=' . $count . '&scope=' . $scope;
$cache = './cache/' . sha1($url) . '.json';
if (file_exists($cache) && filemtime($cache) > time() - 60 * 60){
$jsonData = json_decode(file_get_contents($cache));
}
else {
// Получаю JSON с ответом из API и сохраняю
$jsonData = json_decode(file_get_contents($url));
file_put_contents($cache,json_encode($jsonData));
}
$result = '<div id="instagram">';
foreach ($jsonData->data as $key => $value) {
$result .= '<img src="' . $value->images->low_resolution->url . '" alt="' . $value->caption->text . '" width="' . $width . '" height="' . $height . '" /></a>';
}
$result .= '</div>';
return $result;
}
print get_instagram();
$count
, it doesn’t work anymore, it only works to a lesser extent :( pagination
) next_url
....
}
else {
// Получаю JSON-ы с ответами из API
$first_url = json_decode(file_get_contents($url));
$next_url = json_decode(file_get_contents($first_url->pagination->next_url));
// Сшиваю два объекта в один
$jsonData = (object) array_merge_recursive((array) $first_url, (array) $next_url);
// Сохраняю
file_put_contents($cache, json_encode($jsonData));
}
...
next_url
) write your own handler, and then stitch the objects together? Maybe tell me a function (algorithm) how to simplify this task? :)
Answer the question
In order to leave comments, you need to log in
For one request more than 34 photos will not receive means. Use the MAX_ID and MIN_ID parameters to load data in batches.
Vit - rightly noted, look at this:
github /mgp25/Instagram-API
maybe it will help you (ps I use it for posting myself)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question