我正在使用Javascript的FB登录文档中的代码。但它并不能获取用户的电子邮件地址。它正在使用旧版本...但它不适用于我的应用程序版本(v2.4)。我也使用facebook登录按钮。
以下是我所拥有的:
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId: '1650558335190396',
cookie: true,
xfbml: true,
version: 'v2.4'
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
(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/es_LA/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name + response.id);
document.getElementById('status').innerHTML =
'Thanks for logging in, <br>' + response.name + '<br>' + response.id + '<br> <img src="http://graph.facebook.com/' + response.id + '/picture" /></br>' + response.email;
});
}
这是按钮部分:
<fb:login-button scope="email,user_birthday,user_about_me" autologoutlink="true" onlogin="checkLoginState();">
</fb:login-button>
答案 0 :(得分:2)
FB.api('/me?fields=name,email', function(response) {...
在更改日志中搜索“声明字段”:https://developers.facebook.com/docs/apps/changelog#v2_4