1
votes

Instagram how to get latest Instagram images right now it is fetching oldest images

I am using that code -

function insta( $api_url ){
    $connection_c = curl_init(); // initializing
    curl_setopt( $connection_c, CURLOPT_URL, $api_url ); // API URL to connect
    curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
    curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
    $json_return = curl_exec( $connection_c ); // connect and get json data
    curl_close( $connection_c ); // close connection
    return json_decode( $json_return ); // decode and return
}
$return = insta("https://graph.instagram.com/me/media?fields=id,caption&access_token=xyz");

why only 25 images is coming ?

This is the docu which I followed - 1 - https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

2 - https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media

1
Do you have a link to the API documentation? Does it specify the default number of images returned? - Nigel Ren
@NigelRen i mentioned doc in my question and i did not see any default number - sumeet bajaj
In the response JSON, do you have the "paging values? Perhaps you need to keep on calling it to get the extra images. - Nigel Ren
@NigelRen yes I think paging values will be there but I need latest 5 images only latest date wise - sumeet bajaj

1 Answers

0
votes

`<?php

$connection_c = curl_init(); // initializing
curl_setopt( $connection_c, CURLOPT_URL, "https://graph.instagram.com/me/media?fields=id&access_token=TOKEN" );
curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); 
curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
$json_return = curl_exec( $connection_c );
curl_close( $connection_c );
$dataArray= json_decode( $json_return, true ); 

        foreach($dataArray["data"] as $key=>$val)
        {

            $connection_c = curl_init(); // initializing
            curl_setopt( $connection_c, CURLOPT_URL, "https://graph.instagram.com/".$val["id"]."?fields=id,media_type,media_url,username,timestamp&access_token=TOKEN" ); // API URL to connect
            curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
            curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
            $json_return = curl_exec( $connection_c ); // connect and get json data
            curl_close( $connection_c ); // close connection
            $mediaArray= json_decode( $json_return, true ); // decode and return
            var_dump($mediaArray);
        }

?>`