本文整理汇总了PHP中LinkedIn::profileNew方法的典型用法代码示例。如果您正苦于以下问题:PHP LinkedIn::profileNew方法的具体用法?PHP LinkedIn::profileNew怎么用?PHP LinkedIn::profileNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedIn
的用法示例。
在下文中一共展示了LinkedIn::profileNew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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));
}
}
}
}
}
//.........这里部分代码省略.........