public function get_instagram()
 {
     // make sure user is logged in
     if (!Auth::user()) {
         return Redirect::to('/')->withInput()->withErrors('You must be logged in to access the Instagram panel.');
     }
     // configure the API values
     $auth_config = array('client_id' => CLIENT_ID, 'client_secret' => CLIENT_SECRET, 'redirect_uri' => REDIRECT_URI);
     // create a new Auth object using the config values
     $auth = new Instagram\Auth($auth_config);
     // authorize app if not already authorized
     if (!Input::get('code')) {
         $auth->authorize();
     }
     // get the code value returned from Instagram
     $code = Input::get('code');
     $title = 'ImgHost - Instagram';
     // save the access token if not already saved
     if (!Session::get('instagram_access_token')) {
         Session::put('instagram_access_token', $auth->getAccessToken($code));
     }
     // create a new Instagram object
     $instagram = new Instagram\Instagram();
     // set the access token on the newly created Instagram object
     $instagram->setAccessToken(Session::get('instagram_access_token'));
     // get the ID of the authorized user
     $current_user = $instagram->getCurrentUser();
     // access the media of the authorized user
     $media = $current_user->getMedia();
     $db_images = DB::table('images')->get();
     return View::make('instagram')->with('title', $title)->with('instagram_images', $media)->with('db_images', $db_images);
 }
 public function profile_buttons($user)
 {
     //check authorization status
     $authorized = get_user_meta($user->ID, $this->fix_name('authorized'), true);
     if ($authorized) {
         $instagram = new Instagram\Instagram();
         $instagram->setAccessToken($authorized);
         $auth_test = $instagram->getCurrentUser();
         $user_name = $auth_test->getUserName();
     } else {
         $auth_test = -1;
         $user_name = 'No User Found';
     }
     //add section to profile page
     $output = '<h3>Registration/Renewal Dates</h3>';
     $output .= '<table class="form-table">';
     $output .= '	<tr>';
     $output .= '		<th><label>Instagram API</label></th>';
     $output .= '		<td>';
     //check to see if we have received an authorization code
     if (isset($_GET['code']) || $authorized && $auth_test) {
         //if we just got one
         if (isset($_GET['code'])) {
             //set up authorization config
             $auth_config = array('client_id' => $this->settings['client_id'], 'client_secret' => $this->settings['client_secret'], 'redirect_uri' => $this->settings['redirect_url'], 'scope' => array('basic'));
             //initialize authorization
             $auth = new Instagram\Auth($auth_config);
             $value = $auth->getAccessToken($_GET['code']);
             //if we were previously authorized
             if ($authorized) {
                 //remove old access token
                 delete_user_meta($user->ID, $this->fix_name('authorized'));
             }
             //save the code to the user's meta
             $authorized = add_user_meta($user->ID, $this->fix_name('authorized'), $value);
             //if we already had one
         } elseif ($authorized) {
             $value = $authorized;
         }
         //display authorization code in disabled input
         $output .= '			Authorized as ' . $user_name . '<br /><span class="description"><a href="' . $this->urls['revoke'] . '">Revoke Access</a></span>';
         //if we haven't received one
     } else {
         //display check box allowing user to save profile and then authorize Instagram API
         $output .= '			<input type="checkbox" name="authorized" value="1" id="authorized" /> <label for="authorized">Authorize API Access</label>';
         if ($auth_test !== -1) {
             $output .= '			<br /><span class="description">Your access token is no longer valid, please re-authorize this API integration.</span>';
         }
     }
     $output .= '		</td>';
     $output .= '	</tr>';
     $output .= '</table>';
     echo $output;
 }
 /**
  * Process actions based on $_GET parameters. Authorize Instagram user.
  * @param arr $options instagram plugin options
  * @param instagram $instagramAuth instagram object
  */
 protected function processPageActions($options, Instagram\Auth $instagramAuth)
 {
     //authorize user
     if (isset($_GET["code"])) {
         $access_token = $instagramAuth->getAccessToken($_GET["code"]);
         if (isset($access_token)) {
             $instagram = new Instagram\Instagram($access_token);
             $instagram_user_profile = $instagram->getCurrentUser()->getData();
             $instagram_username = $instagram_user_profile->username;
             $instagram_user_id = $instagram_user_profile->id;
             $this->saveAccessToken($instagram_user_id, $access_token, $instagram_username);
         } else {
             $error_msg = "Problem authorizing your instagram account! Please correct your plugin settings.";
             $this->addErrorMessage($error_msg, 'authorization', true);
         }
     }
 }
<?php

$auth = new Instagram\Auth($auth_config['instagram']);
// If a code is present try and get the access token
// otherwise redirect to the Instagram auth page to get the code
if (isset($_REQUEST['code'])) {
    try {
        $_SESSION['instagram_access_token'] = $auth->getAccessToken($_REQUEST['code']);
        header('Location: ' . REDIRECT . 'migrate');
        exit;
    } catch (\Instagram\Core\ApiException $e) {
        $error = $_SERVER["HTTP_REFERER"] . 'Instragram - ' . ucwords($e->getMessage());
        require APP_DIR . '/views/_header.php';
        require APP_DIR . '/views/_error.php';
        require APP_DIR . '/views/_footer.php';
        exit;
    }
} else {
    $auth->authorize();
}
 public function getInstaAction($id)
 {
     $auth_config = array('client_id' => 'bc7bb286c6834142af582ef9a6029279', 'client_secret' => '02bf67931e8b40509b463a63bd299733', 'redirect_uri' => 'http://hashtag.stuartfeldt.com', 'scope' => array('likes', 'comments', 'relationships'));
     $auth = new \Instagram\Auth($auth_config);
     $auth->authorize();
     return new JsonResponse(array('test' => $auth->getAccessToken($code)));
 }