function instagram_authorize() { global $xoousersultra_captcha_loader, $xoouserultra, $blog_id; //require_once(ABSPATH . 'wp-includes/pluggable.php'); require_once ABSPATH . 'wp-admin/includes/user.php'; require_once xoousers_path . "libs/instagram/instagram.class.php"; $YOUR_APP_KEY = $xoouserultra->get_option('instagram_client_id'); $YOUR_APP_SECRET = $xoouserultra->get_option('instagram_client_secret'); $YOUR_APP_CALLBACK = $xoouserultra->get_option('instagram_redirect_uri'); if ($xoouserultra->get_option('instagram_connect') == 1 && $YOUR_APP_KEY && $YOUR_APP_SECRET && $YOUR_APP_CALLBACK) { if (isset($_GET['code']) && isset($_REQUEST['instagram']) && $_REQUEST['instagram'] == '1') { $instagram = new Instagram(array('apiKey' => $YOUR_APP_KEY, 'apiSecret' => $YOUR_APP_SECRET, 'apiCallback' => $YOUR_APP_CALLBACK)); $code = $_GET['code']; // Receive OAuth token object $data = $instagram->getOAuthToken($code); // Take a look at the API response $user = $data->user->username; $fullname = $data->user->full_name; $bio = $data->user->bio; $website = $data->user->website; $id = $data->user->id; $access_token = $data->access_token; //check access token is set or not if (!empty($user)) { //if user data get successfully if (isset($id)) { //check if $users = get_users(array('meta_key' => 'xoouser_ultra_instagram_id', 'meta_value' => $id, 'meta_compare' => '=')); if (isset($users[0]->ID) && is_numeric($users[0]->ID)) { $returning = $users[0]->ID; $returning_user_login = $users[0]->user_login; } else { $returning = ''; } // Authorize user if (is_user_logged_in()) { update_user_meta($user_id, 'xoouser_ultra_instagram_id', $id); $this->login_registration_afterlogin(); } else { //the user is NOT logged in if ($returning != '') { $noactive = false; /*If alreayd exists*/ $user = get_user_by('login', $returning_user_login); $user_id = $user->ID; if (!$this->is_active($user_id) && !is_super_admin($user_id)) { $noactive = true; } if (!$noactive) { $secure = ""; //already exists then we log in wp_set_auth_cookie($user_id, true, $secure); do_action('wp_login', $user->user_login, $user); } //redirect user $this->login_registration_afterlogin(); } else { if ($user != '' && username_exists($user)) { //user email exists then we have to sync $user_id = username_exists($user); $user = get_userdata($user_id); update_user_meta($user_id, 'xoouser_ultra_instagram_id', $id); $u_user = $user->user_login; $noactive = false; /*If alreayd exists*/ $user = get_user_by('login', $u_user); $user_id = $user->ID; if (!$this->is_active($user_id) && !is_super_admin($user_id)) { $noactive = true; } if (!$noactive) { $secure = ""; //already exists then we log in wp_set_auth_cookie($user_id, true, $secure); do_action('wp_login', $user->user_login, $user); } //redirect user $this->login_registration_afterlogin(); } else { //user is new we have to create it //this is a new client we have to create the account $u_name = $this->get_social_services_name('instagram', $data->user); $u_email = $id; //generat random password $user_pass = wp_generate_password(12, false); $user_login = $this->unique_user('instagram', $data->user); $user_login = sanitize_user($user_login, true); //Build user data $user_data = array('user_login' => $user_login, 'display_name' => $u_name, 'user_email' => $u_email, 'user_pass' => $user_pass); // Create a new user $user_id = wp_insert_user($user_data); update_user_meta($user_id, 'xoouser_ultra_social_signup', 7); update_user_meta($user_id, 'xoouser_ultra_instagram_id', $id); update_user_meta($user_id, 'first_name', $u_name); update_user_meta($user_id, 'display_name', $u_name); $verify_key = $this->get_unique_verify_account_id(); update_user_meta($user_id, 'xoouser_ultra_very_key', $verify_key); $this->user_account_status($user_id); //notify client $xoouserultra->messaging->welcome_email($u_email, $user_login, $user_pass); $creds['user_login'] = sanitize_user($user_login); $creds['user_password'] = $user_pass; $creds['remember'] = 1; $noactive = false; if (!$this->is_active($user_id) && !is_super_admin($user_id)) { $noactive = true; } if (!$noactive) { $user = wp_signon($creds, false); do_action('wp_login', $user->user_login, $user); } //redirect user $this->login_registration_afterlogin(); } } } } } } } }
$check = ''; $code = ''; // Receive OAuth code parameter if (!isset($_SESSION["check"]) && strlen($_GET["code"]) < 50) { $code = $_GET["code"]; //echo "$code<br>"; $_SESSION["check"] = $code; } $code = $_SESSION["check"]; //echo "$code<br>"; //echo strlen($code); //echo "$code<br>"; // Check whether the user has granted access if (true === isset($code) && strlen($code) < 50) { //echo "true hit<br>"; //echo "passed<br>"; //$data = $instagram->getInstagramPhotos($code); //echo $data; // Receive OAuth token object if (!isset($_SESSION[$token])) { //echo "session not set<br>"; $data = $instagram->getOAuthToken($code); $_SESSION[$token] = $data; //echo "session = ".$_SESSION[$token]; $instagram->setAccessToken($data); } else { $var = $_SESSION[$token]; //echo "session = ".$_SESSION[$token]; $instagram->setAccessToken($var); } }
function register_instagram() { $options_check = get_option('si_options'); $config = array('apiKey' => $options_check['instagram_app_id'], 'apiSecret' => $options_check['instagram_app_secret'], 'apiCallback' => site_url() . '/wp-admin/admin-ajax.php?action=register_instagram'); if (isset($_GET['code'])) { $options_check = get_option('si_options'); $instagram = new Instagram($config); $token = $instagram->getOAuthToken($_GET['code']); if (isset($token->access_token)) { update_option('si_oauth', $token->access_token); } else { update_option('si_oauth', 'error'); } } if (strlen($options_check['instagram_app_id']) > 0 && strlen($options_check['instagram_app_secret']) > 0) { $set = 1; } else { $set = 0; } $auth_check = get_option('si_oauth'); if (strlen($auth_check) > 0) { $auth = 1; } else { $auth = 0; } ?> <head> <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> <link href='<?php echo plugins_url('admin/assets/css/iframe.css', __FILE__); ?> ' rel='stylesheet' type='text/css'> <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> </head> <?php if ($auth == 0) { $instagram = new Instagram($config); // Display the login button $loginUrl = $instagram->getLoginUrl(); ?> <div class="instagram"> <span><i class="fa fa-instagram"></i></span><a href="<?php echo $loginUrl; ?> " target="_blank">Login with Instagram</a> </div> <script> setTimeout(function(){ location.reload(); },5000); </script> <?php } else { if ($auth_check == 'error') { //Error with auth $instagram = new Instagram($config); // Display the login button $loginUrl = $instagram->getLoginUrl(); ?> <p>Whoops! It looks like there's a problem with your App credentials. Please check your entries in Step 02 and then use the button below to authorize the app once again.</p> <div class="instagram"> <span><i class="fa fa-instagram"></i></span><a href="<?php echo $loginUrl; ?> " target="_blank">Login with Instagram</a> </div> <script> setTimeout(function(){ location.reload(); },5000); </script> <?php } else { //We have auth credentials, check to make sure they haven't expired $instagram = new Instagram($config); $instagram->setAccessToken($auth_check); $user = $instagram->getUser(); if (isset($user->data->username)) { ?> <h2>Success!</h2> <p>Alright! You're all set up and ready to go!</p> <?php } else { //Auth token has expired. Show login button instead. $instagram = new Instagram($config); // Display the login button $loginUrl = $instagram->getLoginUrl(); ?> <p>Whoops! It looks like your authorization has expired. Please use the button below to authorize the app once again.</p> <div class="instagram"> <span><i class="fa fa-instagram"></i></span><a href="<?php echo $loginUrl; ?> " target="_blank">Login with Instagram</a> </div> <script> setTimeout(function(){ location.reload(); },5000); </script> <?php } ?> <?php } } exit; }
function hba_admin() { require_once 'instagram/instagram.php'; if (get_settings('HBA_INSTA_CLIENT_ID') != false || get_settings('HBA_INSTA_CLIENT_SECRET') != false) { $instagram = new Instagram(array('apiKey' => get_option('HBA_INSTA_CLIENT_ID'), 'apiSecret' => get_option('HBA_INSTA_CLIENT_SECRET'), 'apiCallback' => site_url() . '/wp-admin/options-general.php?page=themeOptions.php')); } if ($_REQUEST['saved']) { echo '<div id="message" class="updated fade"><p><strong>' . THEMENAME . ' settings saved.</strong></p></div>'; } ?> <h2><?php echo THEMENAME; ?> settings</h2> <form method="post" class="<?php echo THEMENAME; ?> _settings"> <div class="formRow"> <label for="phone_number">Phone Number</label> <input name="phone_number" id="phone_number" type="text" value="<?php if (get_settings('phone_number') != '') { echo get_settings('phone_number'); } ?> " /></div> <?php if ($_REQUEST['rm_hba_insta'] == true) { delete_option('HBA_INSTA_CLIENT_ID'); delete_option('HBA_INSTA_CLIENT_SECRET'); delete_option('HBA_INSTA_AUTH'); } if (get_settings('HBA_INSTA_CLIENT_ID') === false || get_settings('HBA_INSTA_CLIENT_SECRET') === false) { ?> <div class="formRow"> <label for="HBA_INSTA_CLIENT_ID">Client ID</label> <input type="text" name="HBA_INSTA_CLIENT_ID" value="<?php if (get_settings('HBA_INSTA_CLIENT_ID') != '') { echo get_settings('HBA_INSTA_CLIENT_ID'); } ?> " /> </div> <div class="formRow"> <label for="HBA_INSTA_CLIENT_SECRET">Client Secret</label> <input type="text" name="HBA_INSTA_CLIENT_SECRET" value="<?php if (get_settings('HBA_INSTA_CLIENT_SECRET') != '') { echo get_settings('HBA_INSTA_CLIENT_SECRET'); } ?> "> </div> <?php } if ($_GET['code'] == false && get_settings('HBA_INSTA_AUTH') === false && get_settings('HBA_INSTA_CLIENT_ID') != '' && get_settings('HBA_INSTA_CLIENT_SECRET') != '') { echo "<a href='{$instagram->getLoginUrl()}'>Sign in with Instagram</a>"; } ?> <?php if ($_GET['code'] != false && get_settings('HBA_INSTA_AUTH') == false) { $code = $_GET['code']; $data = $instagram->getOAuthToken($code); update_option('HBA_INSTA_AUTH', $data); } if (get_settings('HBA_INSTA_AUTH') != false) { echo 'Successfully authenticated with instagram. <a href="' . site_url() . '/wp-admin/options-general.php?page=themeOptions.php&rm_hba_insta=true">Remove user</a>'; } ?> <p class="submit"> <input name="save" type="submit" value="Save changes" class="saveButton" /> <input type="hidden" name="action" value="save" /> </p> </form> <?php }
} } $conf = array('apiKey' => 'e55f12fa633f403784037ba7dc72e684', 'apiSecret' => '1247122a9f0d46dd9c4ba84d96d5d030', 'apiCallback' => 'http://localhost/instagram'); $ig = new Instagram($conf); $scopes = array('basic', 'likes', 'comments', 'relationships'); ?> <a href="<?php echo $ig->getLoginUrl($scopes); ?> ">Login</a> <?php $users = $ig->searchUser('maanmughal87', 1); echo '<pre>users:'; print_r($users); $code = $_GET['code']; $data = $ig->getOAuthToken($code); echo '<pre>'; print_r($data); // set user access token $ig->setAccessToken($data); // get all user likes $likes = $ig->getUserLikes(); // take a look at the API response echo '<pre>likes'; print_r($likes); echo '<pre>'; // get all user likes $follows = $ig->getUserFollows(); // take a look at the API response echo '<pre>follows'; print_r($follows);
<?php /* Example to get access token. */ require_once 'aimee.instagram.class.php'; $ig = new Instagram($client_id = "x", $client_secret = "y", $redirect_uri = "z"); $url = $ig->getLoginURL(); if (isset($_GET['code'])) { $code = $_GET['code']; // posts the code to Instagram and returns the access token from IG $token = $ig->getOAuthToken($code); // Copy and paste or store this token in a database so you can do setAccessToken() in bot.php echo 'Access token: . ' . $token . ' (copy and paste or store this in a database).'; } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Access Token Example</title> </head> <body> <p><a href="<?php echo $url; ?> ">Authentication link.</a></p> </body> </html>