$max_id = !empty($_REQUEST['max_id']) ? $_REQUEST['max_id'] : null;
$mediaList = array();
// Return empty JSON object if an access token session isnt present
if (!isset($_SESSION['instagram_access_token'])) {
    exit(return_json(array(), null, 'You are not authenticated in Instagram!'));
}
$instagram = new Instagram\Instagram();
$instagram->setAccessToken($_SESSION['instagram_access_token']);
$current_user = $instagram->getCurrentUser();
try {
    if (DEBUG) {
        $username = !empty($_REQUEST['user']) ? $_REQUEST['user'] : $current_user->getUserName();
    } else {
        $username = $current_user->getUserName();
    }
    $user = $instagram->getUserByUsername($username);
    $userId = $user->getId();
    try {
        $params = array('max_id' => $max_id);
        $media = $user->getMedia($params);
        foreach ($media as $photo) {
            $location = array('id' => null, 'lat' => null, 'lon' => null);
            if ($photo->hasLocation()) {
                //	Location ID (Instagram Proprietary - look like a FourSquare V1 venueId)
                if ($photo->getLocation()->getId()) {
                    $location['id'] = $photo->getLocation()->getId();
                }
                //	Latitude & Longitude
                $location['lat'] = $photo->getLocation()->getLat();
                $location['lon'] = $photo->getLocation()->getLng();
                //	Location Name
<?php

require "../vendor/autoload.php";
$instagram = new \Instagram\Instagram();
try {
    //Login
    $instagram->login("username", "password");
    //Find User by Username
    $user = $instagram->getUserByUsername("liamcarncottle");
    //Get Feed of User by Id
    $userFeed = $instagram->getUserFeed($user);
    //Iterate over Items in Feed
    foreach ($userFeed->getItems() as $feedItem) {
        //User Object, (who posted this)
        $user = $feedItem->getUser();
        //Caption Object
        $caption = $feedItem->getCaption();
        //How many Likes?
        $likeCount = $feedItem->getLikeCount();
        //How many Comments?
        $commentCount = $feedItem->getCommentCount();
        //Get the Comments
        $comments = $feedItem->getComments();
        //Which Filter did they use?
        $filterType = $feedItem->getFilterType();
        //Grab a list of Images for this Post (different sizes)
        $images = $feedItem->getImageVersions2()->getCandidates();
        //Grab the URL of the first Photo in the list of Images for this Post
        $photoUrl = $images[0]->getUrl();
        //todo: Do something with it :)
        //Output the Photo URL