Esempio n. 1
0
 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);
 }
 /**
  * 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);
         }
     }
 }
Esempio n. 3
0
 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)));
 }
Esempio n. 4
0
<?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 profile_auth($user_id)
 {
     //if the user wants to authorize
     if (isset($_REQUEST['authorized'])) {
         //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);
         //authorize
         $auth->authorize();
     }
 }