linkedin - Linkedin JavaScript SDK 并不总是返回用户的电子邮件地址
问题描述
我正在尝试使用 LinkedIn JavaScript SDK 在我的网站上集成 LinkedIn 登录功能,但它并不总是返回用户的电子邮件地址。有时会,有时不会。
这是我的代码。
加载 API:
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: MY_API_KEY
authorize: true
onLoad: onLinkedInLoad
</script>
这个函数在 API 加载时被调用:
function onLinkedInLoad() {
/*
* Defining the scope
*/
var scope = {scope: 'r_emailaddres'};
/*
* If the user is not authorized, attach a click event hander with .li-login button
*/
if( !IN.User.isAuthorized() ) {
$('.li-login').on('click', function( event ){
event.preventDefault();
IN.User.authorize(function(){
getProfileData( false );
}, scope);
});
}
else{
IN.Event.on(IN, "auth", function(data){
console.log(data)
getProfileData( true );
});
}
}
getProfileData( alreadyLoggedin ) 函数定义:
function getProfileData( alreadyLoggedin) {
if(alreadyLoggedin){
IN.API.Raw("/people/~:(id,firstName,lastName,emailAddress,picture-url)").result(function(response){
$('.li-modal .user-fullname').html(response.firstName+' '+response.lastName);
$('.li-modal img').attr('src', response.pictureUrl);
$('.li-login').removeClass('li-login-btn');
console.log(response)
}).error(onError);
}
else{
IN.API.Raw("/people/~:(id,firstName,lastName,emailAddress,picture-url)").result(function( response ){
console.log(response);
var data = {
"first_name": response.firstName,
"last_name": response.lastName,
"email": response.emailAddress,
"service": 'linkedin',
"picture": response.pictureUrl,
};
//attemptLogin(data);
}).error(onError);
}
}
登录按钮代码:
<a href="#" class="li-login"><img src="images/linkedin-icon.png"></a>
快速帮助将不胜感激。
解决方案
推荐阅读
- android - 在所有设备上仅使用一个注册领域用户
- javascript - 多个状态在 React 中共享相同的视图或组件
- android - 避免清洁任务的 gradle 构建参数
- java - Android studio gradle 与 firebase 同步错误:响应 204:No Content 没有内容
- progressive-web-apps - 内容的后台同步
- git - 克隆 git 存储库后不是 git 存储库
- ruby-on-rails - Ruby On Rails 将 JSON 转换为 firebase
- r - 使用 R 的 bizdays 包为每日股价数据创建工作日日历的问题
- python - 在 pyspark 中选择包含字符串的列
- jquery - 通过 tbody 而不是 tr 元素进行 DataTable 分页