Simple way to get instagram recent images using php and instagram api, get instagram access token and get your recent images easily.

How To Get Instagram Recent Images

Using Instagram API and PHP cURL, we will get instagram recent images easily.

Register a New Client

Firstly, go to instagram developer and register a new client, like this:

instagram api register a new client


Now we will use PHP cURL via Qassim_HTTP() function:

function Qassim_HTTP($method, $url, $header, $data){
    /* By Qassim Hassan, */

    if( $method == 1 ){
        $method_type = 1; // 1 = POST
        $method_type = 0; // 0 = GET

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_HEADER, 0);

    if( $header !== 0 ){
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

    curl_setopt($curl, CURLOPT_POST, $method_type);

    if( $data !== 0 ){
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

    $response = curl_exec($curl);
    $json = json_decode($response, true);

    return $json;

Get Instagram Access Token

Now in your “redirect uri” page file, add this code to get access token (enter client id and client secret and redirect uri):

if( isset($_GET['code']) ){
    /* By Qassim Hassan, */
    $data = http_build_query(
            "client_id" => "xxxx", // enter your client id.
            "client_secret" => "xxxx", // enter your client secret.
            "grant_type" => "authorization_code", // do not change it!.
            "redirect_uri" => "xxxx", // enter your redirect uri.
            "code" => $_GET['code']

    $url = "";

    $result = Qassim_HTTP(1, $url, 0, $data);

    echo 'This is your access token, save it: '.$result['access_token'];


Now open this link in browser to get access token (enter client id and redirect uri):

You will get access token, save it:

get instagram access token

Get Instagram Recent Images

Now we will get instagram recent images, using this code (enter access token):

/* By Qassim Hassan, */
$access_token = "xxxx"; // enter your access token.

$count = 5; // enter count of recent images.

$url = "$access_token&count=$count";

$result = Qassim_HTTP(0, $url, 0, 0);

foreach ( $result['data'] as $image ) {
    echo '<p><img src="'.$image['images']['standard_resolution']['url'].'"></p>';

Download Example

You can download full code here.