Exemplo 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);
 }
Exemplo n.º 2
0
 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)
 /**
  * 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);
         }
     }
 }
Exemplo n.º 5
0
<?php

require '../vendor/autoload.php';
try {
    $instagram = new \Instagram\Instagram();
    $instagram->login('username', 'password');
    var_dump($instagram->getCurrentUser());
} catch (\Exception $e) {
    echo $e->getMessage();
}
 public function get_images($user_id, $count = null)
 {
     if (!$user_id) {
         global $post;
         $user_id = $post->post_author;
     }
     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_' . $user_id . '_' . $count));
         if (!$return_array) {
             $instagram = new Instagram\Instagram();
             $instagram->setAccessToken($token);
             $current_user = $instagram->getCurrentUser();
             $images = $current_user->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_' . $user_id . '_' . $count));
                 delete_transient($this->fix_name('images_' . $user_id . '_' . $count . '_long'));
                 set_transient($this->fix_name('images_' . $user_id . '_' . $count), $return_array, $short_term * 60 * 60);
                 set_transient($this->fix_name('images_' . $user_id . '_' . $count . '_long'), $return_array, 84600);
             } else {
                 $return_array = get_transient($this->fix_name('images_' . $user_id . '_' . $count . '_long'));
                 if (!$return_array) {
                     $return_array = false;
                 }
             }
         }
         return $return_array;
     } else {
         return false;
     }
 }