仅使用cUrl从Instagram中提取内容

I am trying to show Instagram content from a user (mines) on a website. My client-side page would make an AJAX request to my server-side script, which in turn, would do the necessary stuff to pull the content from Instagram API (using cUrl) and send back a JSON response.

Sadly, I am little bit confused with the Authentication instructions, particularly Step One: Direct your user to our authorization URL.

In order to get an access_token to work with the API, I need to pass client_id, redirect_uri, and code. I have the client_id and redirect_uri. The problem is the last item, code, which gets found after redirecting from https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code. The redirected page will be REDIRECT-URI?code=CODE which has the CODE to use to make the request to get the access_token.

Is there a way to "automate" this last part ? Or more precisely, is it possible to make a request (using cUrl) and then grabbing this CODE

Hopefully, this is clear. Unlike other APIs, Instagram seems to make things difficult. My goal is so that when users come on the page, they will see a gallery of images from my Instagram account. They shouldn't need to log into Instagram or do anything to see these images.

Edit

$clientId = 'XXX';
$clientSecret = 'YYY';
$redirectUri = 'ZZZ';

// step 1: authorize
$url = "https://instagram.com/oauth/authorize/?client_id={$clientId}&redirect_uri={$redirectUri}&response_type=code";

try {
    $ch = curl_init();
    curl_setopt_array($ch, array(  
        CURLOPT_CONNECTTIMEOUT => 30,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_URL => $url
    ));
    $data = json_decode(curl_exec($ch), true);

    // how to get CODE from response?

    curl_close($ch);
} catch(Exception $e) {
    echo $e->getMessage();
}