我已经为我的网站实现了领英认证。我的意思是登录领英按钮使用php oauth类。但无法获取邮箱地址。在那之后,我尝试了javascript。即使我不能。显示了一些错误。
所以谁能发帖或给出想法来获得电子邮件地址?
谢谢。
对于version, V2使用下面的简单代码。
<?php
$config['callback_url'] = ''; //Your callback URL
$config['Client_ID'] = ''; // Your LinkedIn Application Client ID
$config['Client_Secret'] = ''; // Your LinkedIn Application Client Secret
?>
<?php
echo '<a href="https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id='.$config['Client_ID'].'&redirect_uri='.$config['callback_url'].'&state=98765EeFWf45A53sdfKef4233&scope=r_liteprofile r_emailaddress w_member_social"><img src="./images/linkedin_connect_button.png" alt="Sign in with LinkedIn"/></a>'; //Button code and scope url.
?>
<?php
if(isset($_GET['code'])) // get code after authorization
{
$url = 'https://www.linkedin.com/uas/oauth2/accessToken';
$param = 'grant_type=authorization_code&code='.$_GET['code'].'&redirect_uri='.$config['callback_url'].'&client_id='.$config['Client_ID'].'&client_secret='.$config['Client_Secret'];
//$return = (json_decode(post_curl($url,$param),true)); // Request for access token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //Remote Location URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Return data instead printing directly in Browser
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 7); //Timeout after 7 seconds
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt($ch, CURLOPT_HEADER, 0);
//We add these 2 lines to create POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, $param); //parameters data
$result = curl_exec($ch);
curl_close($ch);
$return = (json_decode($result,true));
print_r($return);
if($return['error']) // if invalid output error
{
$content = 'Some error occured<br><br>'.$return['error_description'].'<br><br>Please Try again.';
}
else // token received successfully
{
$url = "https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))&oauth2_access_token=".$return['access_token'];
//step1
$cSession = curl_init();
//step2
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
//step3
$result = curl_exec($cSession);
//step4
curl_close($cSession);
$return = (json_decode($result,true));
print_r($return);
}
}
?>
email地址只对认证用户有效
执行以下GET调用来获取已验证用户的电子邮件地址:
得到http://api.linkedin.com/v1/people/(电子邮件地址):
希望对你有帮助