function HandleResponse() { $config = (include "/config.php"); $li = new LinkedIn(array('api_key' => $config['linkedin_client_id'], 'api_secret' => $config['linkedin_client_secret'], 'callback_url' => $config['domain'] . "/linkedin/login/success")); $token = $li->getAccessToken($_REQUEST['code']); $_SESSION['linkedin_token'] = $token; echo "<script>window.close();</script>"; die; }
function getData() { $session = JFactory::getSession(); $post = JRequest::get('post'); $redsocialhelper = new redsocialhelper(); $login = $redsocialhelper->getsettings(); if (!isset($post['generatetoken'])) { return JText::_('PLEASE_SELECT_SECTION'); } switch ($post['generatetoken']) { case 'facebook': $fb_profile_id = $session->set('fb_profile_id', $post['fb_profile_id']); $app_id = $login['app_id']; $app_secret = $login['app_secret']; require_once JPATH_SITE . '/components/com_redsocialstream/helpers/facebook/facebook.php'; $redirect_url = urlencode(JURI::base() . "index.php?option=com_redsocialstream&view=access_token"); header("location: https://www.facebook.com/dialog/oauth?client_id=" . $login['app_id'] . "&redirect_uri=" . $redirect_url . "&scope=manage_pages,publish_stream&manage_pages=1&publish_stream=1"); break; case 'linkedin': //Linkedin APi Key $api_key = $login['linked_api_key']; //Linkedin Secret Key $secret_key = $login['linked_secret_key']; $redirect_url = JURI::base() . "index.php?option=com_redsocialstream&view=access_token"; $linkedin_profile_id = $session->set('linkedin_profile_id', $post['linkedin_profile_id']); $API_CONFIG = array('appKey' => $api_key, 'appSecret' => $secret_key, 'callbackUrl' => $redirect_url); $linkedin = new LinkedIn($API_CONFIG); $response = $linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { $session->set('oauthReqToken', $response['linkedin']); // redirect the user to the LinkedIn authentication/authorisation page to initiate validation. header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); exit; } break; } }
protected function getUserIdFromApi() { // Create a LinkedIn object $linkedInApiConfig = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => APP_URL . '/' . Content::l() . '/login/linkedincallback/' . (!empty($_GET['nextPage']) ? $_GET['nextPage'] : '')); $linkedIn = new LinkedIn($linkedInApiConfig); try { $response = $linkedIn->retrieveTokenAccess($_GET['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); } catch (Error $e) { Debug::l('Error. Could not retrieve LinkedIn access token. ' . $e); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } if ($response['success'] === TRUE) { // The request went through without an error, gather user's access tokens $_SESSION['oauth']['linkedin']['access'] = $response['linkedin']; // Set the user as authorized for future quick reference $_SESSION['oauth']['linkedin']['authorized'] = true; } else { $this->exitWithMessage('Error. The OAuth access token was not retrieved. ' . print_r($response, 1)); } $this->accessToken = serialize($response['linkedin']); /* Retrieve the user ID The XML response will look like one of these: <person> <id>8GhzNjjaOi</id> </person> <error> <status>401</status> <timestamp>1288518358054</timestamp> <error-code>0</error-code> <message>[unauthorized]. The token used in the OAuth request is not valid.</message> </error> */ try { $response = $linkedIn->profile('~:(id,first-name,last-name)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); if ($response['linkedin']->getName() != 'person') { Debug::l('Error. Could not retrieve person data from LinkedIn. ' . print_r($response, 1)); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } } else { Debug::l('Error. Could not retrieve person data from LinkedIn. ' . print_r($response, 1)); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } $this->linkedInId = (string) $response['linkedin']->id; $this->name = $response['linkedin']->{'first-name'} . ' ' . $response['linkedin']->{'last-name'}; } catch (Error $e) { Debug::l('Error. Could not retrieve person ID from LinkedIn. ' . $e); header('Location: ' . APP_URL . '/' . Content::l() . '/login/linkedin/'); exit; } }
function testNET_API_LinkedIn() { $LinkedIn = new LinkedIn(); $res = $LinkedIn->Login('*****@*****.**', 'dfgsd'); $this->assertTrue($res, "Can't login to LinkedIn"); $Profile = $LinkedIn->GetProfileByID(8418679); //7202602); $this->assertTrue($Profile, "Can't get LinkedIn profile"); $res = $Profile->GetPersonalDetails(); $this->assertTrue($res && count($res), "Can't get LinkedIn personal details"); $res = $Profile->GetInterests(); $this->assertTrue($res, "Can't get LinkedIn interests"); $res = $Profile->GetEmailAddress(); $this->assertTrue($res, "Can't get LinkedIn email address"); $res = $Profile->GetJobTitle(); $this->assertTrue($res, "Can't get LinkedIn job title"); $res = $Profile->GetExperience(); $this->assertTrue($res, "Can't get LinkedIn experience block"); $res = $Profile->GetEducation(); $this->assertTrue($res, "Can't get LinkedIn education block"); $connections = $LinkedIn->GetConnectionsList(); $this->assertTrue(count($connections), "No connections found"); }
public function demo() { session_start(); $this->load->helper('url'); $this->load->library('linkedin'); $config['base_url'] = base_url('home/linkedin'); $config['callback_url'] = base_url('home/demo'); $config['linkedin_access'] = '75cmijp7gpecgv'; $config['linkedin_secret'] = 'CkLc98T2vkqc4vEh'; # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']); //$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])) { $_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier']; $linkedin->request_token = unserialize($_SESSION['requestToken']); $linkedin->oauth_verifier = $_SESSION['oauth_verifier']; $linkedin->getAccessToken($_REQUEST['oauth_verifier']); $_SESSION['oauth_access_token'] = serialize($linkedin->access_token); header("Location: " . $config['callback_url']); exit; } else { $linkedin->request_token = unserialize($_SESSION['requestToken']); $linkedin->oauth_verifier = $_SESSION['oauth_verifier']; $linkedin->access_token = unserialize($_SESSION['oauth_access_token']); } # You now have a $linkedin->access_token and can make calls on behalf of the current member $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,email-address,headline,picture-url)"); /* echo '<pre>'; echo 'My Profile Info'; echo $xml_response; echo '<br />'; echo '</pre>';*/ $id = $linkedin->getProfile('~:(id)'); $email = $linkedin->getProfile('~:(email-address)'); $uid = trim(strip_tags($id)); $email_address = trim(strip_tags($email)); $response = $this->home->linkedinauth($email_address); if ($response == 1) { $this->home->set_online_status(1); if ($this->session->userdata('is_login')) { if ($this->session->userdata('is_alumni')) { redirect(base_url('alumni')); } elseif ($this->session->userdata('is_prospective')) { redirect(base_url('parents')); } else { redirect(base_url('seeker')); } } } else { redirect(base_url('home')); } $this->data['view_file'] = 'index'; echo Modules::run('template/home', $this->data); }
function get_resume_data() { $this->_check_auth(); $API_CONFIG = $this->config->item('LINKEDIN_KEYS'); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($this->session->userdata('access')); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON); $resumeResponse = $OBJ_linkedin->profile('~:(first-name,last-name,formatted-name,industry,skills,summary,specialties,positions,picture-url,educations,interests,headline,phone-numbers,email-address,member-url-resources)'); if ($resumeResponse['success'] === TRUE) { $resumeData = json_decode($resumeResponse['linkedin'], true); //print_r($resumeData); $this->load->model('resume'); $userId = $this->session->userdata('user_id'); $resumeData = array(); $resumeData['user_id'] = $userId; $resumeData['json_data'] = $resumeResponse['linkedin']; $resumeData['update_date'] = date('Y-m-d h:i:s'); if (!$this->resume->exist($userId)) { $resumeData['create_date'] = date('Y-m-d h:i:s'); $resumeId = $this->resume->create($resumeData); } else { $resumeId = $this->resume->update_user_id($userId, $resumeData); } redirect('/builder/customize/' . $resumeId, 'refresh'); } }
protected function getAPI() { $OAuth2 = nxcSocialNetworksOAuth2::getInstanceByType('linkedin'); $OAuth2Token = $OAuth2->getToken(); $API = new LinkedIn(array('appKey' => $OAuth2->appSettings['key'], 'appSecret' => $OAuth2->appSettings['secret'], 'callbackUrl' => null)); $API->setTokenAccess(array('oauth_token' => $OAuth2Token->attribute('token'), 'oauth_token_secret' => $OAuth2Token->attribute('secret'))); return $API; }
function sfsi_getlinkedin_follower($ln_company, $APIsettings) { require_once SFSI_DOCROOT . '/helpers/linkedin-api/linkedin-api.php'; $url = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $linkedin = new LinkedIn($APIsettings['ln_api_key'], $APIsettings['ln_secret_key'], $APIsettings['ln_oAuth_user_token'], $url); $followers = $linkedin->getCompanyFollowersByName($ln_company); return strip_tags($followers); }
function sfsi_getlinkedin_follower($ln_company, $APIsettings) { require_once SFSI_DOCROOT . '/helpers/linkedin-api/linkedin-api.php'; $scheme = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https" : "http"; $url = $scheme . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $linkedin = new LinkedIn($APIsettings['ln_api_key'], $APIsettings['ln_secret_key'], $APIsettings['ln_oAuth_user_token'], $url); $followers = $linkedin->getCompanyFollowersByName($ln_company); return strip_tags($followers); }
public function onSloginCheck() { $redirect = JURI::base() . '?option=com_slogin&task=check&plugin=linkedin'; $app = JFactory::getApplication(); $input = $app->input; $oauth_problem = $input->getString('oauth_problem', ''); if ($oauth_problem == 'user_refused') { $config = JComponentHelper::getParams('com_slogin'); JModel::addIncludePath(JPATH_ROOT . '/components/com_slogin/models'); $model = JModel::getInstance('Linking_user', 'SloginModel'); $redirect = base64_decode($model->getReturnURL($config, 'failure_redirect')); $controller = JControllerLegacy::getInstance('SLogin'); $controller->displayRedirect($redirect, true); } # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback $linkedin = new LinkedIn($this->params->get('api_key'), $this->params->get('secret_key'), $redirect); //$linkedin->debug = true; $oauth_verifier = $input->getString('oauth_verifier', ''); $requestToken = unserialize($app->getUserState('requestToken')); $linkedin->request_token = $requestToken; $linkedin->oauth_verifier = $app->getUserState('oauth_verifier'); if (!empty($oauth_verifier)) { $app->setUserState('oauth_verifier', $oauth_verifier); $linkedin->getAccessToken($oauth_verifier); $app->setUserState('oauth_access_token', serialize($linkedin->access_token)); header("Location: " . $redirect); exit; } else { $linkedin->access_token = unserialize($app->getUserState('oauth_access_token')); } # You now have a $linkedin->access_token and can make calls on behalf of the current member //$request = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url)"); $request = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url,email-address)?format=json"); $request = json_decode($request); if (empty($request)) { echo 'Error - empty user data'; exit; } else { if (!empty($request->errorCode)) { echo 'Error - ' . $request->message; exit; } } $returnRequest = new SloginRequest(); $returnRequest->first_name = $request->firstName; $returnRequest->last_name = $request->lastName; // $returnRequest->email = $request->email; $returnRequest->id = $request->id; $returnRequest->real_name = $request->firstName . ' ' . $request->lastName; $returnRequest->display_name = $request->firstName; $returnRequest->all_request = $request; return $returnRequest; }
function Share() { $config = (include "/config.php"); $li = new LinkedIn(array('api_key' => $config['linkedin_client_id'], 'api_secret' => $config['linkedin_client_secret'], 'callback_url' => $config['domain'] . "/linkedin/login/success")); $li->setAccessToken($_SESSION['linkedin_token']); $li->setState($_SESSION['linkedin_state']); $hasParams = false; $comment = ""; $title = ""; $description = ""; $url = ""; $source = ""; $visiblity = ""; if (isset($_POST['title']) && $_POST['title'] != "") { $hasParams = true; $title = $_POST['title']; } if (isset($_POST['description']) && $_POST['description'] != "") { $hasParams = true; $description = $_POST['description']; } if (isset($_POST['url']) && $_POST['url'] != "") { $hasParams = true; $url = $_POST['url']; } if (isset($_POST['source']) && $_POST['source'] != "") { $hasParams = true; $source = $_POST['source']; } if (isset($_POST['comment']) && $_POST['comment'] != "") { $comment = $_POST['comment']; } if (isset($_POST['visiblity']) && $_POST['visiblity'] != "") { $visiblity = $_POST['visiblity']; } else { $visiblity = "anyone"; } if (!$hasParams) { return "Missing params"; exit; } $post = array('comment' => $comment, 'content' => array('title' => $title, 'description' => $description, 'submitted_url' => $url, 'submitted_image_url' => $source), 'visibility' => array('code' => $visiblity)); //echo $li->getAccessToken(); try { $li->post('/people/~/shares', $post); } catch (Exception $ex) { return $ex->getMessage(); } return 'success'; }
private function _startLinkedinHandshake($req_type, $credentials) { $session = self::oauth_session_exists(); $app = JFactory::getApplication(); require_once dirname(__FILE__) . DS . 'jobboard' . DS . 'lib' . DS . 'linkedin' . DS . 'linkedin_3.1.1.class.php'; $API_CONFIG = array('appKey' => $credentials['key'], 'appSecret' => $credentials['secret'], 'callbackUrl' => null); switch ($req_type) { case 'initiate': $API_CONFIG['callbackUrl'] = JURI::root() . 'index.php?option=com_jobboard&view=user&task=getlinkedinprof&' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1&Itemid=' . $this->_itemid; $OBJ_linkedin = new LinkedIn($API_CONFIG); $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { $response = $OBJ_linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { $session_oauth = $session->get('oauth'); $session_oauth['oauth']['linkedin']['request'] = $response['linkedin']; $session->set('oauth', $session_oauth); $app->redirect(LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { $msg = JText::_('PLG_JOBBOARD_REQUEST_TOKEN_RETRIEVAL_FAILED'); $app->redirect('index.php?option=com_jobboard&view=user&task=addcv&Itemid=' . $this->_itemid, $msg, 'error'); } } else { self::_processResponse(&$OBJ_linkedin); } return self::_getLinkedInProfile(&$OBJ_linkedin); break; case 'revoke': $session_oauth = $session->get('oauth'); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($session_oauth['oauth']['linkedin']['access']); $response = $OBJ_linkedin->revoke(); if ($response['success'] === TRUE) { if ($session->clear('oauth')) { $msg = JText::_('PLG_JOBBOARD_AUTH_REVOKE_SUCCESS'); $msg_type = 'Message'; } else { $msg = JText::_('PLG_JOBBOARD_SESSION_CLEAR_FAILED'); $msg_type = 'error'; } } else { $msg = JText::_('PLG_JOBBOARD_AUTH_REVOKE_FAILED'); $msg_type = 'error'; } $app->redirect('index.php?option=com_jobboard&view=user&task=addcv&Itemid=' . $this->_itemid, $msg, $msg_type); break; default: break; } }
private function loadProfiles($person, $personIsUser) { $profiles = array(); if (!empty($person['facebook_access_token']) && (!$personIsUser || $this->mergeNetwork != 'Facebook')) { try { //$params = array('access_token' => $user['facebook_access_token']); $facebookProfile = SessionManager::getInstance()->getFacebook()->api('/' . $person['facebook_id']); } catch (FacebookApiException $e) { Debug::l('Error loading Facebook profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e); } if (isset($facebookProfile)) { $profiles[] = '<a href="' . $facebookProfile['link'] . '" target="_blank" class="profile"><img src="https://graph.facebook.com/' . $person['facebook_id'] . '/picture?type=square" /> ' . $facebookProfile['name'] . ' on Facebook</a>'; } } if (!empty($person['linkedin_access_token']) && (!$personIsUser || $this->mergeNetwork != 'LinkedIn')) { $API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => ''); $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess(unserialize($person['linkedin_access_token'])); try { $linkedInProfile = $OBJ_linkedin->profile('id=' . $person['linkedin_id'] . ':(first-name,last-name,public-profile-url,picture-url)'); } catch (ErrorException $e) { Debug::l('Error loading LinkedIn profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e); } if ($linkedInProfile['success'] === TRUE) { $linkedInProfile['linkedin'] = new SimpleXMLElement($linkedInProfile['linkedin']); if ($linkedInProfile['linkedin']->getName() == 'person') { $li_pr = (string) $linkedInProfile['linkedin']->{'public-profile-url'}; $li_pi = (string) $linkedInProfile['linkedin']->{'picture-url'}; $li_fn = (string) $linkedInProfile['linkedin']->{'first-name'}; $li_ln = (string) $linkedInProfile['linkedin']->{'last-name'}; $profiles[] = '<a href="' . $li_pr . '" target="_blank" class="profile"><img src="' . $li_pi . '" /> ' . $li_fn . ' ' . $li_ln . ' on LinkedIn</a>'; } } } if (!empty($person['twitter_access_token']) && ($personIsUser || $this->mergeNetwork != 'Twitter')) { try { $twitterAccessToken = unserialize($person['twitter_access_token']); $twitter = new TwitterOAuth(TW_CONSUMER, TW_SECRET, $twitterAccessToken['oauth_token'], $twitterAccessToken['oauth_token_secret']); $twitter->format = 'json'; $twitterProfile = $twitter->get('users/show', array('user_id' => $person['twitter_id'])); } catch (ErrorException $e) { Debug::l('Error loading Twitter profile for ' . ($personIsUser ? 'current' : 'other') . ' user. ' . $e); } if (isset($twitterProfile)) { $profiles[] = '<a href="http://twitter.com/' . $twitterProfile->screen_name . '" target="_blank" class="profile"><img src="' . $twitterProfile->profile_image_url . '" /> @' . $twitterProfile->screen_name . ' on Twitter</a>'; } } return $profiles; }
public function linkedinGetLoggedinUserInfo($requestToken = '', $oauthVerifier = '', $accessToken = '') { include_once $this->config['linkedin_library_path']; $linkedin = new LinkedIn($this->config['linkedin_access'], $this->config['linkedin_secret']); $linkedin->request_token = unserialize($requestToken); //as data is passed here serialized form $linkedin->oauth_verifier = $oauthVerifier; $linkedin->access_token = unserialize($accessToken); try { $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url,public-profile-url)"); } catch (Exception $o) { print_r($o); } return $xml_response; }
public function linkedInStatus($status, $requestToken = '', $oauthVerifier = '', $accessToken = '') { include_once 'linkedinoAuth.php'; $linkedin = new LinkedIn($this->config['linkedin_access'], $this->config['linkedin_secret']); $linkedin->request_token = unserialize($requestToken); //as data is passed here serialized form $linkedin->oauth_verifier = $oauthVerifier; $linkedin->access_token = unserialize($accessToken); try { $xml_response = $linkedin->setStatus($status); } catch (Exception $o) { print_r($o); } return $xml_response; }
/** * load the user latest activity * - timeline : all the stream * - me : the user activity only * {@inheritdoc} */ function getUserActivity($stream) { try { if ($stream == "me") { $response = $this->api->updates('?type=SHAR&scope=self&count=25'); } else { $response = $this->api->updates('?type=SHAR&count=25'); } } catch (LinkedInException $e) { throw new Exception("User activity stream request failed! {$this->providerId} returned an error: {$e}"); } if (!$response || !$response['success']) { return array(); } $updates = new SimpleXMLElement($response['linkedin']); $activities = array(); foreach ($updates->update as $update) { $person = $update->{'update-content'}->person; $share = $update->{'update-content'}->person->{'current-share'}; $ua = new Hybrid_User_Activity(); $ua->id = (string) $update->id; $ua->date = (string) $update->timestamp; $ua->text = (string) $share->{'comment'}; $ua->user->identifier = (string) $person->id; $ua->user->displayName = (string) $person->{'first-name'} . ' ' . $person->{'last-name'}; $ua->user->profileURL = (string) $person->{'site-standard-profile-request'}->url; $ua->user->photoURL = null; $activities[] = $ua; } return $activities; }
public function __construct() { session_start(); // Create a LinkedIn object $linkedInApiConfig = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => APP_URL . '/' . Content::l() . '/login/linkedincallback/' . (!empty($_GET['nextPage']) ? $_GET['nextPage'] : '')); $linkedIn = new LinkedIn($linkedInApiConfig); // Send a request for a LinkedIn access token $response = $linkedIn->retrieveTokenRequest(); if ($response['success'] === TRUE) { // Split up the response and stick the LinkedIn portion in the user session $_SESSION['oauth']['linkedin']['request'] = $response['linkedin']; // Redirect the user to the LinkedIn authentication/authorisation page to initiate validation. header('Location: ' . LINKEDIN::_URL_AUTH . $_SESSION['oauth']['linkedin']['request']['oauth_token']); } else { $this->exitWithMessage('Unable to retrieve access token for LinkedIn'); } }
function GetUserInfo() { //Comma seperated list of fields you wish returned // https://developer.linkedin.com/docs/fields/basic-profile if (!isset($_GET['fields']) || $_GET['fields'] == "") { return "Missing required params"; exit; } $config = (include "/config.php"); $li = new LinkedIn(array('api_key' => $config['linkedin_client_id'], 'api_secret' => $config['linkedin_client_secret'], 'callback_url' => $config['domain'] . "/linkedin/login/success")); $li->setAccessToken($_SESSION['linkedin_token']); try { $info = $li->get('/people/~:(' . $_GET['fields'] . ')'); } catch (Exception $ex) { return $ex->getMessage(); } return $info; }
*/ if (!array_key_exists('signature_version', $credentials) || $credentials['signature_version'] != 1) { // invalid/missing signature_version throw new LinkedInException('Invalid/missing signature_version in passed credentials - ' . print_r($credentials, TRUE)); } if (!array_key_exists('signature_order', $credentials) || !is_array($credentials['signature_order'])) { // invalid/missing signature_order throw new LinkedInException('Invalid/missing signature_order in passed credentials - ' . print_r($credentials, TRUE)); } // calculate base signature $sig_order = $credentials['signature_order']; $sig_base = ''; foreach ($sig_order as $sig_element) { $sig_base .= $credentials[$sig_element]; } // calculate encrypted signature $sig_encrypted = base64_encode(hash_hmac('sha1', $sig_base, $API_CONFIG['appSecret'], TRUE)); // finally, check token validity if (!array_key_exists('signature', $credentials) || $sig_encrypted != $credentials['signature']) { // invalid/missing signature throw new LinkedInException('Invalid/missing signature in credentials - ' . print_r($credentials, TRUE)); } // swap tokens $OBJ_linkedin = new LinkedIn($API_CONFIG); $response = $OBJ_linkedin->exchangeToken($credentials['access_token']); // echo out response echo '<pre>' . print_r($response['linkedin'], TRUE) . '</pre>'; } catch (LinkedInException $e) { // exception raised echo $e->getMessage(); }
$linkedin_access = $config_params['linkedin_access']; $linkedin_secret = $config_params['linkedin_secret']; //$sess = new SessionManager(); session_start(); $config['base_url'] = "{$hostname}/linkedin/page1.php"; $config['callback_url'] = "{$hostname}/linkedin/page2.php"; // $config['linkedin_access'] = 'YMKaHlPF6xv8YTMs_FftnoC1tq_0Fgoz9Y8me0PvcR1Sm9WxzuPI18hZr2yP3fFq';//twetest // $config['linkedin_secret'] = 'PuKdmBOQFdR1vibAe0LX3yRkKhu-NWlZaqC3EwnsiiMw1OL0EZ_J_rmh5PjzHXfg';//twetest $config['linkedin_access'] = $linkedin_access; //twetest $config['linkedin_secret'] = $linkedin_secret; //twetest include_once $docroot . "/linkedin/linkedin.php"; logger("Ln/Page2: Top"); # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']); //$linkedin->debug = true; if (isset($_REQUEST['oauth_verifier'])) { $_SESSION['oauth_verifier'] = $_REQUEST['oauth_verifier']; $linkedin->request_token = unserialize($_SESSION['requestToken']); $linkedin->oauth_verifier = $_SESSION['oauth_verifier']; $linkedin->getAccessToken($_REQUEST['oauth_verifier']); logger("Ln/Page2: access token1: ", $linkedin->access_token); $_SESSION['oauth_access_token'] = serialize($linkedin->access_token); header("Location: " . $config['callback_url']); exit; } else { $linkedin->request_token = unserialize($_SESSION['requestToken']); $linkedin->oauth_verifier = $_SESSION['oauth_verifier']; $linkedin->access_token = unserialize($_SESSION['oauth_access_token']); logger("Ln/Page2: access token2: ", $linkedin->access_token);
} else { ?> <ul> <li><a href="#manage">Manage LinkedIn Authorization</a></li> </ul> <?php } ?> <hr /> <h2 id="manage">Manage LinkedIn Authorization:</h2> <?php if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { // user is already connected $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']); ?> <form id="linkedin_revoke_form" action="<?php echo $_SERVER['PHP_SELF']; ?> " method="get"> <input type="hidden" name="<?php echo LINKEDIN::_GET_TYPE; ?> " id="<?php echo LINKEDIN::_GET_TYPE; ?> " value="revoke" /> <input type="submit" value="Revoke Authorization" /> </form>
<?php session_start(); include 'lib/myclass.php'; $config['base_url'] = $obj->SITEURL . 'acesslinkeddata.php'; $config['callback_url'] = $obj->SITEURL . 'demo.php'; $config['linkedin_access'] = '75vkqc3tq7hrwp'; $config['linkedin_secret'] = 'VpK3l3fMS3hMna7f'; include_once "linkedin.php"; # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']); //$linkedin->debug = true; # Now we retrieve a request token. It will be set as $linkedin->request_token $linkedin->getRequestToken(); $_SESSION['requestToken'] = serialize($linkedin->request_token); # With a request token in hand, we can generate an authorization URL, which we'll direct the user to //echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n"; header("Location:" . $linkedin->generateAuthorizeUrl());
default: // nothing being passed back, display demo page // check PHP version if (version_compare(PHP_VERSION, '5.0.0', '<')) { throw new LinkedInException('You must be running version 5.x or greater of PHP to use this library.'); } // check for cURL if (extension_loaded('curl')) { $curl_version = curl_version(); $curl_version = $curl_version['version']; } else { throw new LinkedInException('You must load the cURL extension to use this library.'); } $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE; if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($_SESSION['oauth']['linkedin']['access']); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_XML); // check if the viewer is a member of the test group $response = $OBJ_linkedin->group(DEMO_GROUP, ':(relation-to-viewer:(membership-state))'); if ($response['success'] === TRUE) { $result = new SimpleXMLElement($response['linkedin']); $membership = $result->{'relation-to-viewer'}->{'membership-state'}->code; $in_demo_group = $membership == 'non-member' || $membership == 'blocked' ? FALSE : TRUE; } else { // request failed echo "Error retrieving group membership information: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>"; } ?> </ul> <?php
public function get_linkedin_url() { $config['base_url'] = base_url('auth/get_linkedin_url'); $config['callback_url'] = base_url('auth/linkedin_login'); $config['linkedin_access'] = '78iwuorjnrw04c'; $config['linkedin_secret'] = 'J05AYZ236vVmIc3e'; $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url']); $linkedin->getRequestToken(); $_SESSION['requestToken'] = serialize($linkedin->request_token); echo $linkedin->generateAuthorizeUrl(); }
/** * Function to post Message to Linkedin on various actions * @param array $userData * @param string $statusMessage * @author Rohan Julka * */ public function postToLinkedin($userData, $statusMessage) { require_once ROOT . DS . APP_DIR . DS . 'Plugin/linkedin/linkedin.php'; $ln = new LinkedIn(Configure::read('linkedinApiKey'), Configure::read('linkedinApiSecret')); $ln->setTokenData($userData['User']['linkedin_access_token']); //$user = $ln->fetch('GET', '/v1/people/~:(firstName,lastName)'); //print "Hello $user->firstName $user->lastName."; try { $ln->fetch('POST', '/v1/people/~/shares', array('comment' => $statusMessage, 'visibility' => array('code' => 'anyone'))); } catch (Exception $e) { $this->Session->setFlash('Unable to post to Linkedin', 'Front/flash_bad'); } }
public function getLinkedinData($linkedinProfiles) { $mainframe = JFactory::getApplication(); $params = $mainframe->getparams(); $limit = $params->get('limit'); $linkedinDataList = array(); if (count($linkedinProfiles) > 0) { $accessLinkedin = RedSocialStreamHelper::getLinkinAccessToken(); include_once JPATH_COMPONENT . '/helpers/twitter/statuses.php'; $twitterStatuses = new TwitterStatuses(); foreach ($linkedinProfiles as $twitterProfile) { if (isset($accessLinkedin->access_token) && !empty($accessLinkedin->access_token)) { $tweetList = $twitterStatuses->getUserTimeline($twitterProfile['title'], $accessLinkedin->access_token, $limit); for ($i = 0; $i < count($tweetList); $i++) { $tweet = $tweetList[$i]; $linkedinDataList[$twitterProfile['id']]['data'] = $tweet; $linkedinDataList[$twitterProfile['id']]['profile_id'] = $twitterProfile['id']; $linkedinDataList[$twitterProfile['id']]['title'] = ''; $linkedinDataList[$twitterProfile['id']]['type'] = TWITTER; $linkedinDataList[$twitterProfile['id']]['group_id'] = $twitterProfile['group_id']; $linkedinDataList[$twitterProfile['id']]['source_link'] = "https://twitter.com/" . $tweet->user->screen_name . "/status" . $tweet->id_str; $linkedinDataList[$twitterProfile['id']]['thumb_uri'] = $tweet->user->profile_image_url; if (isset($tweet->text)) { $linkedinDataList[$twitterProfile['id']]['message'] = addslashes($tweet->text); } $linkedinDataList[$twitterProfile['id']]['ext_profile_id'] = $tweet->user->id; $linkedinDataList[$twitterProfile['id']]['ext_post_id'] = $tweet->id_str; $linkedinDataList[$twitterProfile['id']]['ext_post_name'] = $tweet->user->screen_name; $linkedinDataList[$twitterProfile['id']]['duration'] = ''; $linkedinDataList[$twitterProfile['id']]['created_time'] = date("Y-m-d H:i:s", strtotime($tweet->created_at)); $linkedinDataList[$twitterProfile['id']]['published'] = 1; } } } } return $linkedinDataList; $api_key = $login['linked_api_key']; // Linkedin Api key $secret_key = $login['linked_secret_key']; //Linkedin Secret key $access_tokens = $this->getLinkedinAccessToken(); include JPATH_SITE . '/components/com_redsocialstream/helpers/linkedin/linkedin.php'; require_once JPATH_SITE . '/components/com_redsocialstream/helpers/twitter/OAuth.php'; $API_CONFIG = array('appKey' => $api_key, 'appSecret' => $secret_key, 'callbackUrl' => ""); $linkedin = new LinkedIn($API_CONFIG); $access_token = $access_tokens[0]->linkedin_token; $access_secret = $access_tokens[0]->linkedin_secret; $token = array("oauth_token" => $access_token, "oauth_token_secret" => $access_secret); $linkedin->setTokenAccess($token); $query = '?type=SHAR&count=30'; $response = $linkedin->updates($query); if ($response['success'] === TRUE) { $updates = new SimpleXMLElement($response['linkedin']); if ((int) $updates['total'] > 0) { $i = 0; foreach ($updates->update as $update) { $person = $update->{'update-content'}->person; $share = $update->{'update-content'}->person->{'current-share'}; $linkedinlist[$i]['data'] = $update; $linkedinlist[$i]['created_time'] = date("Y-m-d", trim($share->timestamp)); $linkedinlist[$i]['type'] = 'linkedin'; $savedata[$i]['group_id'] = $linkedlistdata['group_id']; $savedata[$i]['type'] = LINKEDIN; $savedata[$i]['ext_profile_id'] = $person->{id}; $savedata[$i]['ext_post_id'] = $share->{id}; $savedata[$i]['ext_post_name'] = $person->{'first-name'} . ' ' . $person->{'last-name'}; if (isset($share->comment)) { $savedata[$i]['message'] = addslashes($share->comment); } $savedata[$i]['title'] = ''; $savedata[$i]['source_link'] = $person->{'site-standard-profile-request'}->url; $savedata[$i]['created_time'] = date("Y-m-d", trim($share->timestamp)); $savedata[$i]['duration'] = ''; $savedata[$i]['profile_id'] = $linkedlistdata['profile_id']; $savedata[$i]['published'] = 1; $savedata[$i]['thumb_uri'] = $person->{'picture-url'}; $i++; } } } if (isset($savedata)) { $this->savePost($savedata); } return $linkedinlist; }
public function us_fan_counts() { header('content-type: application/json'); $ajax_debug = UltimateSocialDeux::opt('us_ajax_debug', false); if (wp_verify_nonce($_REQUEST['nonce'], 'us_nonce') || $ajax_debug) { if (!class_exists('Requests')) { require_once plugin_dir_path(__FILE__) . '/includes/Requests.php'; Requests::register_autoloader(); } $args = $_REQUEST['args'] ? $_REQUEST['args'] : die('Args not set'); $args = urldecode(stripslashes($args)); $args = json_decode($args, true); $option = maybe_unserialize(get_option('us_fan_counts', array())); $json = array(); $networks = explode(',', $args['networks']); $networks = array_keys(array_flip($networks)); $timestamp = time(); foreach ($networks as $key => $network) { $option[$network]['count'] = isset($option[$network]['count']) ? $option[$network]['count'] : 0; $json[$network]['count'] = $option[$network]['count']; $option[$network]['timestamp'] = $timestamp; $id = ''; $key = ''; $secret = ''; $api = ''; $app = ''; $user = ''; $name = ''; $username = ''; switch ($network) { case 'facebook': $app_token = UltimateSocialDeux::opt('us_facebook_token'); $fb_token = $app_token ? "?access_token=" . $app_token : ''; $id = UltimateSocialDeux::opt('us_facebook_id'); if ($id) { $requests[$network] = array('url' => "https://graph.facebook.com/" . $id . $fb_token); } break; case 'twitter': $id = UltimateSocialDeux::opt('us_twitter_id'); $key = UltimateSocialDeux::opt('us_twitter_key'); $secret = UltimateSocialDeux::opt('us_twitter_secret'); if ($id && $key && $secret) { $token = get_option('us_fan_count_twitter_token'); if (!$token) { $credentials = $key . ':' . $secret; $encode = base64_encode($credentials); $args = array('method' => 'POST', 'httpversion' => '1.1', 'blocking' => true, 'headers' => array('Authorization' => 'Basic ' . $encode, 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'), 'body' => array('grant_type' => 'client_credentials')); add_filter('https_ssl_verify', '__return_false'); $response = wp_remote_post('https://api.twitter.com/oauth2/token', $args); $keys = json_decode(wp_remote_retrieve_body($response)); if (!isset($keys->errors) && $keys) { update_option('us_fan_count_twitter_token', $keys->access_token); $token = $keys->access_token; } } $requests[$network] = array('url' => 'https://api.twitter.com/1.1/users/show.json?screen_name=' . $id, 'headers' => array('Authorization' => "Bearer {$token}")); } break; case 'google': $id = UltimateSocialDeux::opt('us_google_id'); $key = UltimateSocialDeux::opt('us_google_key'); if ($key && $id) { $requests[$network] = array('url' => "https://www.googleapis.com/plus/v1/people/" . $id . "?key=" . $key); } break; case 'behance': $id = UltimateSocialDeux::opt('us_behance_id'); $api = UltimateSocialDeux::opt('us_behance_api'); if ($id && $api) { $requests[$network] = array('url' => "http://www.behance.net/v2/users/" . $id . "?api_key=" . $api); } break; case 'delicious': $id = UltimateSocialDeux::opt('us_delicious_id'); if ($id) { $requests[$network] = array('url' => "http://feeds.delicious.com/v2/json/userinfo/" . $id); } break; case 'linkedin': $id = UltimateSocialDeux::opt('us_linkedin_id'); $app = UltimateSocialDeux::opt('us_linkedin_app'); $api = UltimateSocialDeux::opt('us_linkedin_api'); if (!class_exists('LinkedIn')) { require_once plugin_dir_path(__FILE__) . 'includes/linkedin/linkedin.php'; } if (!class_exists('OAuthServer')) { require_once plugin_dir_path(__FILE__) . 'includes/OAuth/OAuth.php'; } if ($id && $api && $id) { $count = 0; $opt = array('appKey' => $app, 'appSecret' => $api, 'callbackUrl' => ''); $api_call = new LinkedIn($opt); $response = $api_call->company(trim('universal-name=' . $id . ':(num-followers)')); if ($ajax_debug) { print_r($response); } if (false !== $response['success']) { $company = new SimpleXMLElement($response['linkedin']); if (isset($company->{'num-followers'})) { $count = intval(current($company->{'num-followers'})); } } $option[$network]['count'] = $count; $json[$network]['count'] = $count; } break; case 'youtube': $id = UltimateSocialDeux::opt('us_youtube_id'); if ($id) { $requests[$network] = array('url' => "http://gdata.youtube.com/feeds/api/users/" . $id . "?alt=json"); } break; case 'soundcloud': $id = UltimateSocialDeux::opt('us_soundcloud_id'); $user = UltimateSocialDeux::opt('us_soundcloud_username'); if ($id && $user) { $requests[$network] = array('url' => 'http://api.soundcloud.com/users/' . $user . '.json?client_id=' . $id); } break; case 'vimeo': $id = UltimateSocialDeux::opt('us_vimeo_id'); if ($id) { $requests[$network] = array('url' => "http://vimeo.com/api/v2/channel/" . $id . "/info.json"); } break; case 'dribbble': $id = UltimateSocialDeux::opt('us_dribbble_id'); if ($id) { $requests[$network] = array('url' => "http://api.dribbble.com/" . $id); } break; case 'github': $id = UltimateSocialDeux::opt('us_github_id'); if ($id) { $requests[$network] = array('url' => "https://api.github.com/users/" . $id); } break; case 'envato': $id = UltimateSocialDeux::opt('us_envato_id'); if ($id) { $requests[$network] = array('url' => "http://marketplace.envato.com/api/edge/user:"******".json"); } break; case 'instagram': $api = UltimateSocialDeux::opt('us_instagram_api'); $id = explode(".", $api); if ($api && $id) { $requests[$network] = array('url' => "https://api.instagram.com/v1/users/" . $id[0] . "/?access_token=" . $api); } break; case 'mailchimp': $name = UltimateSocialDeux::opt('us_mailchimp_name'); $api = UltimateSocialDeux::opt('us_mailchimp_api'); $count = 0; if ($name && $api) { if (!class_exists('MCAPI')) { require_once plugin_dir_path(__FILE__) . 'includes/MCAPI.class.php'; } $api = new MCAPI($api); $retval = $api->lists(); if ($ajax_debug) { print_r($retval); } if (count($retval['data']) > 0) { foreach ($retval['data'] as $list) { if ($list['name'] == $name) { $count = intval($list['stats']['member_count']); break; } } } } $option[$network]['count'] = intval($count); $json[$network]['count'] = intval($count); break; case 'vkontakte': $id = UltimateSocialDeux::opt('us_vkontakte_id'); if ($id) { $requests[$network] = array('url' => "http://api.vk.com/method/groups.getById?gid=" . $id . "&fields=members_count"); } break; case 'pinterest': $username = UltimateSocialDeux::opt('us_pinterest_username'); if ($username) { $requests[$network] = array('url' => 'http://www.pinterest.com/' . $username . '/'); } break; case 'flickr': $id = UltimateSocialDeux::opt('us_flickr_id'); $api = UltimateSocialDeux::opt('us_flickr_api'); if ($id && $api) { $requests[$network] = array('url' => "https://api.flickr.com/services/rest/?method=flickr.groups.getInfo&api_key=" . $api . "&group_id=" . $id . "&format=json&nojsoncallback=1"); } break; case 'feedpress': $manual = intval(UltimateSocialDeux::opt('us_feedpress_manual', 0)); $url = UltimateSocialDeux::opt('us_feedpress_url'); if (filter_var($url, FILTER_VALIDATE_URL)) { $requests[$network] = array('url' => $url); } if ($manual) { $option[$network]['count'] = $manual; $json[$network]['count'] = $manual; } break; default: unset($option[$network]); unset($json[$network]); break; } } $responses = !empty($requests) ? Requests::request_multiple($requests) : die('No requests sent.'); foreach ($responses as $network => $data) { switch ($network) { case 'facebook': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['likes']); $json[$network]['count'] = intval($content['likes']); } break; case 'twitter': case 'soundcloud': case 'dribbble': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['followers_count']); $json[$network]['count'] = intval($content['followers_count']); } break; case 'google': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['circledByCount']); $json[$network]['count'] = intval($content['circledByCount']); } break; case 'behance': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['user']['stats']['followers']); $json[$network]['count'] = intval($content['user']['stats']['followers']); } break; case 'delicious': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content[2]['n']); $json[$network]['count'] = intval($content[2]['n']); } break; case 'youtube': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['entry']['yt$statistics']['subscriberCount']); $json[$network]['count'] = intval($content['entry']['yt$statistics']['subscriberCount']); } break; case 'vimeo': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['total_subscribers']); $json[$network]['count'] = intval($content['total_subscribers']); } break; case 'github': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['followers']); $json[$network]['count'] = intval($content['followers']); } break; case 'envato': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['user']['followers']); $json[$network]['count'] = intval($content['user']['followers']); } break; case 'instagram': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['data']['counts']['followed_by']); $json[$network]['count'] = intval($content['data']['counts']['followed_by']); } break; case 'vkontakte': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['response'][0]['members_count']); $json[$network]['count'] = intval($content['response'][0]['members_count']); } break; case 'pinterest': if (isset($responses[$network]->body)) { $html = $responses[$network]->body; if ($ajax_debug) { print_r($html); } $doc = new DOMDocument(); @$doc->loadHTML($html); $metas = $doc->getElementsByTagName('meta'); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if ($meta->getAttribute('name') == 'pinterestapp:followers') { $count = intval($meta->getAttribute('content')); break; } } $option[$network]['count'] = $count; $json[$network]['count'] = $count; } break; case 'flickr': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['group']['members']['_content']); $json[$network]['count'] = intval($content['group']['members']['_content']); } break; case 'feedpress': if (isset($responses[$network]->body)) { $content = $responses[$network]->body; if ($ajax_debug) { print_r($content); } $content = json_decode($content, true); $option[$network]['count'] = intval($content['subscribers']) + $manuel; $json[$network]['count'] = intval($content['subscribers']) + $manuel; } break; } } maybe_serialize(update_option('us_fan_counts', $option)); echo str_replace('\\/', '/', json_encode($json)); } else { die('Nonce not verified'); } die; }
function index() { $API_CONFIG = $this->config->item('LINKEDIN_KEYS'); define('DEMO_GROUP', '4010474'); define('DEMO_GROUP_NAME', 'Simple LI Demo'); define('PORT_HTTP', '80'); define('PORT_HTTP_SSL', '443'); $_REQUEST[LINKEDIN::_GET_TYPE] = isset($_REQUEST[LINKEDIN::_GET_TYPE]) ? $_REQUEST[LINKEDIN::_GET_TYPE] : ''; switch ($_REQUEST[LINKEDIN::_GET_TYPE]) { case 'initiate': // check for the correct http protocol (i.e. is this script being served via http or https) if ($this->input->server('HTTPS') == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } // set the callback url $API_CONFIG['callbackUrl'] = $protocol . '://' . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] != PORT_HTTP || $_SERVER['SERVER_PORT'] != PORT_HTTP_SSL ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'] . '?' . LINKEDIN::_GET_TYPE . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1'; $OBJ_linkedin = new LinkedIn($API_CONFIG); // check for response from LinkedIn $_GET[LINKEDIN::_GET_RESPONSE] = isset($_GET[LINKEDIN::_GET_RESPONSE]) ? $_GET[LINKEDIN::_GET_RESPONSE] : ''; if (!$_GET[LINKEDIN::_GET_RESPONSE]) { // LinkedIn hasn't sent us a response, the user is initiating the connection // send a request for a LinkedIn access token $response = $OBJ_linkedin->retrieveTokenRequest(); if ($response['success'] === TRUE) { // store the request token //$_SESSION['oauth']['linkedin']['request'] = $response['linkedin']; $response['linkedin']['request'] = $response['linkedin']; $this->session->set_userdata($response['linkedin']); // redirect the user to the LinkedIn authentication/authorisation page to initiate validation. header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { // bad token request echo "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } else { $sess = $this->session->all_userdata(); // LinkedIn has sent a response, user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key $response = $OBJ_linkedin->retrieveTokenAccess($sess['request']['oauth_token'], $sess['request']['oauth_token_secret'], $_GET['oauth_verifier']); //$response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { // the request went through without an error, gather user's 'access' tokens //$sess['access'] = $response['linkedin']; $this->session->set_userdata('access', $response['linkedin']); $this->session->set_userdata('authorized', TRUE); // set the user as authorized for future quick reference //save the shit to the db $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($this->session->userdata('access')); $OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON); $userResponse = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url,email-address)'); if ($userResponse['success'] === TRUE) { $userData = json_decode($userResponse['linkedin'], true); $this->load->model('user'); $this->load->model('billing'); if (!$this->user->exist($userData['id'])) { $userId = $this->user->create($userData); $userId = $this->billing->create(FALSE, $userId); $this->session->set_userdata('user_id', $userId); } else { $user = $this->user->get_by_id($userData['id']); $this->session->set_userdata('user_id', $user[0]->id); } } redirect('/builder/get_resume_data', 'refresh'); // redirect the user back to the demo page //header('Location: ' . $_SERVER['PHP_SELF']); } else { echo "Access token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } } break; case 'revoke': // check the session /* if(!$this->oauth_session_exists()) { throw new LinkedInException('This script requires session support, which doesn\'t appear to be working correctly.'); } */ $OBJ_linkedin = new LinkedIn($API_CONFIG); $OBJ_linkedin->setTokenAccess($this->session->userdata('access')); $response = $OBJ_linkedin->revoke(); if ($response['success'] === TRUE) { // revocation successful, clear session $this->session->sess_destroy(); redirect('/marketing', 'refresh'); } else { // revocation failed echo "Error revoking user's token:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre><br /><br />LINKEDIN OBJ:<br /><br /><pre>" . print_r($OBJ_linkedin, TRUE) . "</pre>"; } break; default: } $isLoggedIn = $this->session->userdata('authorized') ? $this->session->userdata('authorized') : FALSE; if ($isLoggedIn) { redirect('/builder/get_resume_data', 'refresh'); } $this->load->model('resume'); $resumeData = $this->resume->get_by_id(1); $resumeJsonData = json_encode($resumeData); $viewData = array('isLoggedIn' => $isLoggedIn, 'json_data' => $resumeJsonData); $this->load->view('marketing/home', $viewData); }