简体   繁体   中英

Instagram Basic display API how to get latest images in PHP?

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

`<?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);
        }

?>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM