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 } else { } ?>
public function linkedin() { try { $API_CONFIG = array('appKey' => '75wpz389ifrzbq', 'appSecret' => 'ZYEG6gBlFhhUAkfR', 'callbackUrl' => NULL); define('DEMO_GROUP', '4010474'); define('DEMO_GROUP_NAME', 'Simple LI Demo'); define('PORT_HTTP', '80'); define('PORT_HTTP_SSL', '443'); $_GET['lType'] = isset($_GET['lType']) ? $_GET['lType'] : ''; switch ($_GET['lType']) { case 'initiate': if ($_SERVER['HTTPS'] == 'on') { $protocol = 'https'; } else { $protocol = 'http'; } $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); $_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']['linkedin']['request'] = $response['linkedin']; header('Location: ' . LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']); } else { 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 { $response = $OBJ_linkedin->retrieveTokenAccess($_SESSION['oauth']['linkedin']['request']['oauth_token'], $_SESSION['oauth']['linkedin']['request']['oauth_token_secret'], $_GET['oauth_verifier']); if ($response['success'] === TRUE) { $_SESSION['oauth']['linkedin']['access'] = $response['linkedin']; $_SESSION['oauth']['linkedin']['authorized'] = TRUE; 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': if (!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($_SESSION['oauth']['linkedin']['access']); $response = $OBJ_linkedin->revoke(); if ($response['success'] === TRUE) { session_unset(); $_SESSION = array(); if (session_destroy()) { header('Location: ' . $_SERVER['PHP_SELF']); } else { echo "Error clearing user's session"; } } else { 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: $_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); $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 { echo "Error retrieving group membership information: <br /><br />RESPONSE:<br /><br /><pre>" . print_r($response, TRUE) . "</pre>"; } } else { } if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { $response = $OBJ_linkedin->profile('~:(id,first-name,last-name,picture-url)'); if ($response['success'] === TRUE) { $response['linkedin'] = new SimpleXMLElement($response['linkedin']); echo "<pre>" . print_r($response['linkedin'], TRUE) . "</pre>"; } else { echo "Error retrieving profile information:<br /><br />RESPONSE:<br /><br /><pre>" . print_r($response) . "</pre>"; } } else { } break; } } catch (LinkedInException $e) { echo $e->getMessage(); } $this->setErrorMessage('success', 'Registered & Login Successfully'); }
<ul> <li>Please note: The Simple-LinkedIn class requires PHP 5+</li> </ul> <hr /> <?php $_SESSION['oauth']['linkedin']['authorized'] = isset($_SESSION['oauth']['linkedin']['authorized']) ? $_SESSION['oauth']['linkedin']['authorized'] : FALSE; if ($_SESSION['oauth']['linkedin']['authorized'] === TRUE) { // user is already connected $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; ?> <ul> <li><a href="#manage">Manage LinkedIn Authorization</a></li> <li><a href="../demo.php#application">Application Information</a></li> <li><a href="../demo.php#profile">Your Profile</a></li> <li><a href="#groups">Groups API</a> <ul> <li><a href="#groupMemberships">Group Memberships</a></li> <li><a href="#groupsSuggested">Suggested Groups</a></li> <li><a href="#manageGroup">Manage '<?php echo DEMO_GROUP_NAME;
public static function linkedin_old() { $id = ESSBSocialFansCounterHelper::get_option('linkedin.id'); $account_type = ESSBSocialFansCounterHelper::get_option('linkedin.account_type', 'company'); $app_key = ESSBSocialFansCounterHelper::get_option('linkedin.app_key'); $app_secret = ESSBSocialFansCounterHelper::get_option('linkedin.app_secret'); $oauth_token = ESSBSocialFansCounterHelper::get_option('linkedin.oauth_token'); $oauth_token_secret = ESSBSocialFansCounterHelper::get_option('linkedin.oauth_token_secret'); if (empty($id) || empty($app_secret) || empty($app_key) || $account_type == 'profile' && (empty($oauth_token) || empty($oauth_token_secret))) { return 0; } $opt = array('appKey' => $app_key, 'appSecret' => $app_secret, 'callbackUrl' => ''); $api = new LinkedIn($opt); if ($account_type == 'company') { $response = $api->company(trim('universal-name=' . $id . ':(num-followers)')); } elseif ($account_type == 'group') { $response = $api->group($id, ':(num-members)'); } else { $api->setTokenAccess(array('oauth_token' => $oauth_token, 'oauth_token_secret' => $oauth_token_secret)); $response = $api->statistics($id); } if (false == $response['success']) { return false; } $xml = new SimpleXMLElement($response['linkedin']); $count = 0; if ($account_type == 'company') { if (isset($xml->{'num-followers'})) { $count = current($xml->{'num-followers'}); } } if ($account_type == 'group') { if (isset($xml->{'num-members'})) { $count = current($xml->{'num-members'}); } } if ($account_type == 'profile') { if (isset($xml->property)) { $count = (string) $xml->property[0]; } } return $count; }