我正在尝试将FB登录与我的html网站集成。我正在使用FB Javascript SDK 2.5版。弹出窗口打开并询问用户用户ID和密码,但不要求电子邮件,公共配置文件,位置等权限,尽管我已在范围参数中提供了所需的权限。以下是我的代码。
HTML code:
<div id="btnFBLogin"> <img style="width: 35%"
src="assets/img/icons/facebookloginbutton.png" />
</div>
初始化FB Javascript SDK并在文档加载时初始化:
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXX',
xfbml : true,
oauth : true,
version : 'v2.5'
});
};
//Load SDK
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
调用FB.login api:
$('#btnFBLogin').on('click',function(){
FB.login(function(response) {
console.log(JSON.stringify(response));
if (response.status === 'connected') {
// Logged into your app and Facebook.
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
});
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}, {scope: 'public_profile,email'});
});
FB.api登录后返回的响应对象(&#39; / me&#39;,功能(响应)仅提供登录用户的全名。虽然它没有给我电子邮件ID我已经在范围参数中发送它。
答案 0 :(得分:0)
您需要在网址中传递请求的字段,如
FB.api('/me?fields=id,first_name,last_name,friends,email',function(response)