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 getUser() { $instagram = new \Instagram\Instagram(); $instagram->setAccessToken(Session::get('instagram_access_token')); $current_user = $instagram->getCurrentUser(); return $current_user; }
<?php function return_json($mediaList = array(), $max_id = null, $error = null) { return json_encode(array('media' => $mediaList, 'error' => $error, 'max_id' => $max_id)); } $error = null; $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)
public function get_hashtag($tag = null, $user_id = null, $count = null) { if (!$tag || !$user_id) { return false; } else { if (!$count || !is_integer($count)) { $count = (int) $this->settings['number_of_photos']; } $token = get_user_meta($user_id, $this->fix_name('authorized'), true); if ($token) { $return_array = get_transient($this->fix_name('images_' . $tag . '_' . $count)); if (!$return_array) { $instagram = new Instagram\Instagram(); $instagram->setAccessToken($token); $hashtag = $instagram->getTag($tag); $images = $hashtag->getMedia(array('count' => $count)); $return_array = $this->convert_array($images); if (count($return_array)) { $short_term = (int) $this->settings['short_term_cache']; delete_transient($this->fix_name('images_' . $tag . '_' . $count)); delete_transient($this->fix_name('images_' . $tag . '_' . $count . '_long')); set_transient($this->fix_name('images_' . $tag . '_' . $count), $return_array, $short_term * 60 * 60); set_transient($this->fix_name('images_' . $tag . '_' . $count . '_long'), $return_array, 84600); } else { $return_array = get_transient($this->fix_name('images_' . $tag . '_' . $count . '_long')); if (!$return_array) { $return_array = false; } } } return $return_array; } else { return false; } } }