本文整理汇总了PHP中LinkedIn::setTokenAccess方法的典型用法代码示例。如果您正苦于以下问题:PHP LinkedIn::setTokenAccess方法的具体用法?PHP LinkedIn::setTokenAccess怎么用?PHP LinkedIn::setTokenAccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedIn
的用法示例。
在下文中一共展示了LinkedIn::setTokenAccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* {@inheritdoc}
*/
function initialize()
{
if (!$this->config["keys"]["key"] || !$this->config["keys"]["secret"]) {
throw new Exception("Your application key and secret are required in order to connect to {$this->providerId}.", 4);
}
if (!class_exists('OAuthConsumer', false)) {
require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
}
require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php";
$this->api = new LinkedIn(array('appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint));
if ($this->token("access_token_linkedin")) {
$this->api->setTokenAccess($this->token("access_token_linkedin"));
}
}
示例2: LinkedIn
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');
}
}
示例3: initialize
/**
* {@inheritdoc}
*/
function initialize()
{
if (!$this->config["keys"]["key"] || !$this->config["keys"]["secret"]) {
throw new Exception("Your application key and secret are required in order to connect to {$this->providerId}.", 4);
}
if (empty($this->config['fields'])) {
$this->config['fields'] = array('id', 'first-name', 'last-name', 'public-profile-url', 'picture-url', 'email-address', 'date-of-birth', 'phone-numbers', 'summary', 'positions');
}
if (!class_exists('OAuthConsumer', false)) {
require_once Hybrid_Auth::$config["path_libraries"] . "OAuth/OAuth.php";
}
require_once Hybrid_Auth::$config["path_libraries"] . "LinkedIn/LinkedIn.php";
$this->api = new LinkedIn(array('appKey' => $this->config["keys"]["key"], 'appSecret' => $this->config["keys"]["secret"], 'callbackUrl' => $this->endpoint));
if ($this->token("access_token_linkedin")) {
$this->api->setTokenAccess($this->token("access_token_linkedin"));
}
}
示例4: getAPI
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;
}
示例5: _startLinkedinHandshake
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;
}
}
示例6: loadProfiles
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;
}
示例7: LinkedIn
?>
<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>
示例8: linkedin
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');
}
示例9: __construct
public function __construct()
{
session_start();
header('Content-type: text/json');
// Get the website user
$userId = SessionManager::getInstance()->getUserId();
$json['result'] = 'true';
// Make sure a user is logged in
if (!isset($userId)) {
$json['result'] = 'false';
$json['title'] = (string) Content::c()->errors->session->title;
$json['message'] = (string) Content::c()->errors->session->no_session;
echo json_encode($json);
exit;
}
// Validate input
if (empty($_POST['introducee1Name']) || empty($_POST['introducee1FacebookId']) && empty($_POST['introducee1LinkedInId']) && empty($_POST['introducee1TwitterId']) || empty($_POST['introducee2Name']) || empty($_POST['introducee2FacebookId']) && empty($_POST['introducee2LinkedInId']) && empty($_POST['introducee2TwitterId'])) {
$json['result'] = 'false';
$json['title'] = (string) Content::c()->errors->input->title;
$json['message'] = (string) Content::c()->errors->input->introduction_not_created;
echo json_encode($json);
exit;
}
// Make sure the introducees are unique
if (!empty($_POST['introducee1FacebookId']) && !empty($_POST['introducee2FacebookId']) && $_POST['introducee1FacebookId'] == $_POST['introducee2FacebookId'] || !empty($_POST['introducee1LinkedInId']) && !empty($_POST['introducee2LinkedInId']) && $_POST['introducee1LinkedInId'] == $_POST['introducee2LinkedInId'] || !empty($_POST['introducee1TwitterId']) && !empty($_POST['introducee2TwitterId']) && $_POST['introducee1TwitterId'] == $_POST['introducee2TwitterId']) {
$json['result'] = 'false';
$json['title'] = (string) Content::c()->errors->input->title;
$json['message'] = (string) Content::c()->errors->input->introduce_to_self;
echo json_encode($json);
exit;
}
// Connect to the database
$db = Database::getInstance();
$introducee1 = new Person(array('name' => $_POST['introducee1Name'], 'facebookId' => !empty($_POST['introducee1FacebookId']) ? $_POST['introducee1FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee1LinkedInId']) ? $_POST['introducee1LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee1TwitterId']) ? $_POST['introducee1TwitterId'] : null));
$introducee2 = new Person(array('name' => $_POST['introducee2Name'], 'facebookId' => !empty($_POST['introducee2FacebookId']) ? $_POST['introducee2FacebookId'] : '', 'linkedInId' => !empty($_POST['introducee2LinkedInId']) ? $_POST['introducee2LinkedInId'] : null, 'twitterId' => !empty($_POST['introducee2TwitterId']) ? $_POST['introducee2TwitterId'] : null));
// See if the introducees are already in our database, that would be nice!
if (!empty($_POST['introducee1FacebookId'])) {
$introducee1->getDataFromFacebookId($_POST['introducee1FacebookId']);
} elseif (!empty($_POST['introducee1LinkedInId'])) {
$introducee1->getDataFromLinkedInId($_POST['introducee1LinkedInId']);
} elseif (!empty($_POST['introducee1TwitterId'])) {
$introducee1->getDataFromTwitterId($_POST['introducee1TwitterId']);
}
if (!empty($_POST['introducee2FacebookId'])) {
$introducee2->getDataFromFacebookId($_POST['introducee2FacebookId']);
} elseif (!empty($_POST['introducee2LinkedInId'])) {
$introducee2->getDataFromLinkedInId($_POST['introducee2LinkedInId']);
} elseif (!empty($_POST['introducee2TwitterId'])) {
$introducee2->getDataFromTwitterId($_POST['introducee2TwitterId']);
}
// Make sure the introducees are still unique
if ($introducee1->getFacebookId() != null && $introducee1->getFacebookId() == $introducee2->getFacebookId() || $introducee1->getLinkedInId() != null && $introducee1->getLinkedInId() == $introducee2->getLinkedInId() || $introducee1->getTwitterId() != null && $introducee1->getTwitterId() == $introducee2->getTwitterId()) {
$json['result'] = 'false';
$json['title'] = (string) Content::c()->errors->input->title;
$json['message'] = (string) Content::c()->errors->input->introduce_to_self;
echo json_encode($json);
exit;
}
// If the introducees aren't in the database yet, add them
$introducee1->addToDatabase();
$introducee2->addToDatabase();
// If the introducees are on LinkedIn, add their public profile URL and picture to the DB
if ($introducee1->getLinkedInId() != null || $introducee2->getLinkedInId() != null) {
// Connect to LinkedIn API
$sth = $db->prepare('SELECT id, access_token FROM linkedin WHERE person_id = :person_id');
$sth->execute(array(':person_id' => $userId));
$userDetails = $sth->fetch(PDO::FETCH_ASSOC);
if (!empty($userDetails['access_token'])) {
$linkedInAccessToken = $userDetails['access_token'];
// Create LinkedIn object
$API_CONFIG = array('appKey' => LI_API_KEY, 'appSecret' => LI_SECRET, 'callbackUrl' => '');
$OBJ_linkedin = new LinkedIn($API_CONFIG);
$OBJ_linkedin->setTokenAccess(unserialize($linkedInAccessToken));
// Which introducees are on LinkedIn?
$profilesToRequest = array();
if ($introducee1->getLinkedInId() != null) {
$profilesToRequest[] = 'id=' . $introducee1->getLinkedInId();
}
if ($introducee2->getLinkedInId() != null) {
$profilesToRequest[] = 'id=' . $introducee2->getLinkedInId();
}
try {
$linkedInProfiles = $OBJ_linkedin->profileNew('::(' . implode(',', $profilesToRequest) . '):(id,public-profile-url,picture-url)');
} catch (ErrorException $e) {
}
if ($linkedInProfiles['success'] === TRUE) {
$linkedInProfiles['linkedin'] = new SimpleXMLElement($linkedInProfiles['linkedin']);
if ($linkedInProfiles['linkedin']->getName() == 'people') {
foreach ($linkedInProfiles['linkedin']->person as $person) {
$id = (string) $person->id;
$url = (string) $person->{'public-profile-url'};
$pic = (string) $person->{'picture-url'};
if ($id && ($url || $pic)) {
$update = $db->prepare('REPLACE INTO temp_linkedin SET linkedin_id = :linkedin_id, time=NOW(), profile_url = :profile_url, picture_url = :picture_url');
$update->execute(array(':linkedin_id' => $id, ':profile_url' => $url, ':picture_url' => $pic));
}
}
}
}
}
//.........这里部分代码省略.........
示例10: updateLinkedInStatus
function updateLinkedInStatus()
{
$API_CONFIG = array('appKey' => LINKEDIN_API_KEY_PUBLIC, 'appSecret' => LINKEDIN_API_KEY_PRIVATE, 'callbackUrl' => NULL);
$sql = "select `username`, `access_token`, `access_token_secret` FROM `love_users` where `linkedin_share` = 1;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$sql = "select count(*) as loves ,count(distinct giver) as givers from love_love where receiver = '" . $row['username'] . "' and at > DATE_SUB(CURDATE(),INTERVAL 7 DAY);";
$result2 = mysql_query($sql);
$row2 = mysql_fetch_assoc($result2);
if ((int) $row2['givers'] > 0 && (int) $row2['loves'] > 0) {
$OBJ_linkedin = new LinkedIn($API_CONFIG);
$OBJ_linkedin->setTokenAccess(array('oauth_token' => $row['access_token'], 'oauth_token_secret' => $row['access_token_secret']));
$response = $OBJ_linkedin->share('new', array('comment' => "This week's love stats: " . $row2['loves'] . " love from " . $row2['givers'] . " people."), FALSE);
//DEBUG OAUTH TOKENS IF NEEDED
/*
if($response['success'] === TRUE) {
error_log("DATA SENT TO LINKEDIN!");
} else {
error_log("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>");
}
*/
}
}
}
示例11: LinkedIn
<?php
header('Content-type: application/json');
require '../config/keys.php';
require '../lib/linkedin/linkedin_3.2.0.class.php';
$API_CONFIG = $linkedin['config'];
$OBJ_linkedin = new LinkedIn($API_CONFIG);
$OBJ_linkedin->setTokenAccess($linkedin['access']);
$OBJ_linkedin->setResponseFormat(LINKEDIN::_RESPONSE_JSON);
$json = $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)');
$info = json_decode($json['linkedin']);
$node = array('name' => $info->formattedName, 'headline' => $info->headline, 'picture_url' => $info->pictureUrl, 'summary' => $info->summary, 'work_history' => $info->positions->values, 'meta' => 'Powered by LinkedIn', 'profile_url' => 'http://www.linkedin.com/in/njhamann');
if ($json['success'] === TRUE) {
if (isset($_GET['raw']) && $_GET['raw'] == '1') {
echo json_encode($info);
} else {
echo json_encode($node);
}
}
示例12: setAccess
public function setAccess($access)
{
$access = EasyBlogHelper::getRegistry($access);
return parent::setTokenAccess(array('oauth_token' => $access->get('token'), 'oauth_token_secret' => $access->get('secret')));
}
示例13: linkedin
function linkedin()
{
$cookie_name = "linkedin_oauth_" . SETTING::linkedInAPI;
//Check if Cookie exists && Login is enabled
if ($this->repository->get_data("linkedinLogin") && isset($_COOKIE[$cookie_name]) && $_COOKIE[$cookie_name]) {
$credentials_json = $_COOKIE[$cookie_name];
// where PHP stories cookies
$credentials = json_decode($credentials_json);
// validate signature
if ($credentials->signature_version == 1) {
if ($credentials->signature_order && is_array($credentials->signature_order)) {
$base_string = '';
// build base string from values ordered by signature_order
foreach ($credentials->signature_order as $key) {
if (isset($credentials->{$key})) {
$base_string .= $credentials->{$key};
} else {
print "missing signature parameter: {$key}";
}
}
// hex encode an HMAC-SHA1 string
$signature = base64_encode(hash_hmac('sha1', $base_string, SETTING::linkedInSecret, true));
// check if our signature matches the cookie's
if ($signature == $credentials->signature) {
//Signature is authentic, use the stuff
require_once 'linkedin_3.3.0.class.php';
$linkedin = new LinkedIn(array('appKey' => SETTING::linkedInAPI, 'appSecret' => SETTING::linkedInSecret, 'callbackUrl' => NULL));
$tokens = $linkedin->exchangeToken($credentials->access_token);
//Find member_id
$sql = "SELECT id, nonce FROM Users WHERE linkedin_id = '" . $credentials->member_id . "'";
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_assoc($result);
$userId = $row["id"];
$this->setSession($row["id"], $row["nonce"]);
//UPDATE LinkedinToken
$sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "' WHERE " . $this->USER_ID . " = " . $userId;
$query = mysql_query($sql);
}
//No member found, check if user already exists based upon usernam = email
if (mysql_num_rows($result) == 0) {
//print_r($tokens);
$linkedin->setTokenAccess($tokens["linkedin"]);
$result = $linkedin->profile("~:(email-address)?format=json");
$result = json_decode($result["linkedin"], true);
$sql = "SELECT id, nonce FROM Users WHERE " . $this->USER_NAME . " = '" . $result["emailAddress"] . "'";
$query = mysql_query($sql);
if (mysql_num_rows($query) == 1) {
//Combination is known
$row = mysql_fetch_assoc($query);
//print_r($row);
$userId = $row["id"];
$this->setSession($row["id"], $row["nonce"]);
//UPDATE LinkedinToken
$sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "', linkedin_id = '" . $credentials->member_id . "' WHERE " . $this->USER_ID . " = " . $userId;
$query = mysql_query($sql);
//Perform import of LinkedIn data
require_once "user.class.php";
$user = new user($userId, $this->errorClass, $this->notificationClass);
$user->getLinkedInData();
} else {
//Combination is not known, create new profile if stated
if ($this->repository->get_data("linkedinRegister") == 1) {
$email = $result["emailAddress"];
$nonce = $this->create_nonce();
$user_ip = $this->repository->get_data('userIPv4');
$email_hash = $this->hash_password($email, $nonce);
//Define the reference number for the user
$sql = "SELECT MAX(`reference_number`) as maximum FROM Users WHERE created_on >= '" . date("Y") . "-01-01' AND created_on <= '" . date("Y") . "-12-31'";
$result = mysql_fetch_assoc(mysql_query($sql));
$reference_number = $result["maximum"] + 1;
//Create public profile hash
$profile_hash = $this->hash_password($reference_number, $nonce);
//INSERT NEW USER TO DB
$query = sprintf("INSERT INTO " . $this->USER_TABLE . " (" . $this->USER_NAME . ", " . $this->USER_IP_REGISTER . ", " . $this->USER_CREATION . ", confirm_hash, nonce, account_status, reference_number, profile_hash) VALUES ('%s','%s', NOW(), '%s','%s', 0,'%s','%s')", $email, $user_ip, $email_hash, $nonce, $reference_number, $profile_hash);
$result = mysql_query($query);
if (!$result) {
$this->errorClass->add_error(202);
} else {
//INSERT Clientnr to DB
$sql = "SELECT * FROM Users WHERE id = " . mysql_insert_id();
$result = mysql_query($sql);
$user = mysql_fetch_assoc($result);
$date = strtotime($user["created_on"]);
$sql = "UPDATE Users SET client_number = \"K" . date('ym', $date) . "" . sprintf('%04d', $user["reference_number"]) . "\" WHERE id = " . $user["id"];
$result = mysql_query($sql);
$this->setSession($user["id"], $nonce);
//UPDATE LinkedinToken
$sql = "UPDATE Users SET linkedin_token = '" . $tokens["linkedin"]["oauth_token"] . "', linkedin_token_secret = '" . $tokens["linkedin"]["oauth_token_secret"] . "', linkedin_id = '" . $credentials->member_id . "' WHERE " . $this->USER_ID . " = " . $user["id"];
$query = mysql_query($sql);
//Perform import of LinkedIn data
require_once "user.class.php";
$user = new user($user["id"], $this->errorClass, $this->notificationClass);
$user->getLinkedInData();
header("Location:" . Setting::baseUrl . "/users/complete_account.php");
exit;
}
} else {
$this->notificationClass->add_note("Het emailadres die je gebruikt bij LinkedIn is niet bij ons bekend. Log in met je emailadres en wachtwoord en koppel je profiel met LinkedIn in je accountinstellingen of <a href=\"index.php?linkedinLogin=1&linkedinRegister=1\">registreer</a> met je LinkedIn account");
}
//.........这里部分代码省略.........
示例14: postFeeds
//.........这里部分代码省略.........
$fb_union_array = array_merge($fb_array, $fbfeeds);
$fb_array = array_unique($fb_union_array);
}
if (count($twitterfeeds) > 0) {
$tw_union_array = array_merge($tw_array, $twitterfeeds);
$tw_array = array_unique($tw_union_array);
}
if (count($linkedinfeeds) > 0) {
$ln_union_array = array_merge($ln_array, $linkedinfeeds);
$ln_array = array_unique($ln_union_array);
}
// For Repost
$repostfeeds = $post['repost'];
for ($r = 0; $r < count($repostfeeds); $r++) {
$article_id = $repostfeeds[$r];
$rePostData = $model->getPostedFeedData($article_id);
if ($rePostData[0]->facebook) {
$fb_repost_arr[] = $rePostData[0]->article_id;
}
if ($rePostData[0]->twitter) {
$tw_repost_arr[] = $rePostData[0]->article_id;
}
if ($rePostData[0]->linkedin) {
$ln_repost_arr[] = $rePostData[0]->article_id;
}
}
if (count($fb_repost_arr) > 0) {
$fb_repost_union_array = array_merge($fb_array, $fb_repost_arr);
$fb_array = array_unique($fb_repost_union_array);
}
if (count($tw_repost_arr) > 0) {
$tw_repost_union_array = array_merge($tw_array, $tw_repost_arr);
$tw_array = array_unique($tw_repost_union_array);
}
if (count($ln_repost_arr) > 0) {
$ln_repost_union_array = array_merge($ln_array, $ln_repost_arr);
$ln_array = array_unique($ln_repost_union_array);
}
// End for Repost
$redsocialhelper = new redsocialhelper();
$login = $redsocialhelper->getsettings();
// For Facebook Post
for ($f = 0; $f < count($fb_array); $f++) {
//Get Article Data
$article = $model->getArticleData($fb_array[$f]);
// For Facebook
$app_id = $login['app_id'];
$app_secret = $login['app_secret'];
$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
$result_fb_token = $redsocialhelper->getFbAccessToken();
$fb_token = $result_fb_token[0]->fb_token;
$profile_id = $result_fb_token[0]->profile_id;
//'413610368700619';
$profile_name = $redsocialhelper->getProfilename($profile_id);
$attachment = array('message' => strip_tags($article[0]->introtext), 'access_token' => $fb_token);
$userWall = $facebook->api('/' . $profile_name . '/feed', 'post', $attachment);
$postedData = $model->savePostedFeedData($fb_array[$f], "facebook");
// End for Facebook
}
// End
// For Twitter Post
for ($t = 0; $t < count($tw_array); $t++) {
//Get Article Data
$article = $model->getArticleData($tw_array[$t]);
//your app's consumer key
$consumer_key = $login['twitter_consumer_key'];
//your app's secret key
$consumer_secret = $login['twitter_consumer_sec'];
$twitter_token_result = $redsocialhelper->getTwitterAccessToken();
$twitter_token = $twitter_token_result[0]->twitter_token;
$twitter_secret = $twitter_token_result[0]->twitter_secret;
$post_feed = strip_tags(substr($article[0]->introtext, 0, 140));
$twitteroauth = new TwitterOAuth($consumer_key, $consumer_secret, $twitter_token, $twitter_secret);
$twitterpost = $twitteroauth->post('statuses/update', array('status' => $post_feed));
$postedData = $model->savePostedFeedData($tw_array[$t], "twitter");
}
// End
// For LinkedIN
for ($l = 0; $l < count($ln_array); $l++) {
//Get Article Data
$article = $model->getArticleData($ln_array[$l]);
// LinkedinApi key
$api_key = $login['linked_api_key'];
//LinkedinSecret key
$secret_key = $login['linked_secret_key'];
$access_tokens = $redsocialhelper->getLinkedinAccessToken();
$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);
$response = $linkedin->updateNetwork(strip_tags(substr($article[0]->introtext, 0, 999)));
$postedData = $model->savePostedFeedData($ln_array[$l], "linkedin");
}
// End for LinkedIN
$msg = JText::_("COM_REDSOCIALSTREAM_FEED_POSTED_SUCCESSFULLY");
$link = 'index.php?option=' . $option . '&view=postfeeds';
$this->setRedirect($link, $msg);
}
示例15: getLinkedinProfile
function getLinkedinProfile($req_type)
{
$session = LinkedinHelper::oauth_session_exists();
$app = JFactory::getApplication();
// include the LinkedIn class
require_once 'linkedin_3.1.1.class.php';
// display constants
$API_CONFIG = array('appKey' => 'r7xckk3gxdfg', 'appSecret' => 'fJQh57Ex2Qg7YyPi', 'callbackUrl' => NULL);
define('CONNECTION_COUNT', 20);
define('PORT_HTTP', '80');
define('PORT_HTTP_SSL', '443');
define('UPDATE_COUNT', 10);
// set index
//$_REQUEST[LINKEDIN::_GET_TYPE] = (isset($_REQUEST[LINKEDIN::_GET_TYPE])) ? $_REQUEST[LINKEDIN::_GET_TYPE] : '';
switch ($req_type) {
case 'initiate':
/**
* Handle user initiated LinkedIn connection, create the LinkedIn object.
*/
// check for the correct http protocol (i.e. is this script being served via http or https)
if (isset($_SERVER['HTTPS'])) {
if ($_SERVER['HTTPS'] == 'on') {
$protocol = 'https';
} else {
$protocol = 'http';
}
} 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'] . '?' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
// $API_CONFIG['callbackUrl'] = JRoute::_('index.php?option=com_jobboard&view=user') . '&' . $req_type . '=initiate&' . LINKEDIN::_GET_RESPONSE . '=1';
// echo $API_CONFIG['callbackUrl'];die;
$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();
//echo 'response: '.'<pre>'.print_r($response, true).'</pre>';
if ($response['success'] === TRUE) {
// store the request token
$session_oauth = $session->get('oauth');
$session_oauth['oauth']['linkedin']['request'] = $response['linkedin'];
$session->set('oauth', $session_oauth);
//redirect the user to the LinkedIn authentication/authorisation page to initiate validation.
$app->redirect(LINKEDIN::_URL_AUTH . $response['linkedin']['oauth_token']);
} else {
$profile_assoc = array();
$profile_assoc['response'] = false;
$profile_assoc['msg'] = "Request token retrieval failed:<br /><br />RESPONSE:<br /><br /><pre>";
return $profile_assoc;
// bad token request
}
} else {
// LinkedIn has sent a response
// user has cancelled LinkedIn authentication
if (JRequest::getString('oauth_problem') == 'user_refused') {
$app->redirect('index.php?option=com_jobboard&view=user&task=addcv', JText::_('COM_JOBBOARD_IMPORTLINKEDINCANCELLED'));
}
// user has granted permission, take the temp access token, the user's secret and the verifier to request the user's real secret key
$session_oauth = $session->get('oauth');
$response = $OBJ_linkedin->retrieveTokenAccess($session_oauth['oauth']['linkedin']['request']['oauth_token'], $session_oauth['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
$session_oauth['oauth']['linkedin']['access'] = $response['linkedin'];
// set the user as authorized for future quick reference
$session_oauth['oauth']['linkedin']['authorized'] = TRUE;
$session->set('oauth', $session_oauth);
} else {
// bad token access
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>";
}
}
$response = $OBJ_linkedin->profile('~:(id,first-name,last-name,summary,educations,positions,skills)');
if ($response['success'] === TRUE) {
$profile = new SimpleXMLElement($response['linkedin']);
$profile_json = json_encode($profile);
$profile_assoc = array_unique(json_decode($profile_json, TRUE), SORT_REGULAR);
$profile_assoc['response'] = $response['success'];
} else {
// profile retrieval failed
$profile_assoc = array();
$profile_assoc['response'] = false;
}
return $profile_assoc;
break;
case 'revoke':
/**
* Handle authorization revocation.
*/
$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) {
// revocation successful, clear session
if ($session->clear('oauth')) {
// session destroyed
//.........这里部分代码省略.........