我无法检索连接Facebook登录按钮的人的Facebook电子邮件地址。我在2.8版本中使用JDK java脚本
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();" auto_logout_link="true"></fb:login-button>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<appId>',
xfbml : true,
version : 'v2.8'
});
FB.AppEvents.logPageView();
};
(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_FR/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function checkLoginState() {
FB.getLoginStatus(function(response) {
//console.log('Check login state');
//console.log(response);
statusChangeCallback(response);
});
}
function statusChangeCallback(response) {
if (response.status === 'connected') {
console.log('Connected');
testAPI();
} else if (response.status === 'not_authorized') {
console.log('Please log into this app');
} else {
console.log('Please log into Facebook.');
}
}
function testAPI() {
FB.login(function(response) {
if (response.authResponse) {
var access_token = response.authResponse.accessToken;
FB.api(
'/me',
{fields: 'id,email,cover,name,first_name,last_name,age_range,link,gender,locale,picture,timezone,updated_time,verified'},
function (response) {
console.log('response');
console.log(response);
}
);
} else {
console.log('User cancelled login or did not fully authorize.');
}
},{scope:'email'});
}
function testLogout() {
FB.logout(function(response) {
console.log(response);
});
}
</script>
我收到了除电子邮件之外的所有信息。你能帮我吗 ?
答案 0 :(得分:1)
变化:
FB.api(
'/me',
{fields: 'id,email,cover,name,first_name,last_name,age_range,link,gender,locale,picture,timezone,updated_time,verified'},
function (response) {
console.log('response');
console.log(response);
}
);
要:
FB.api(
'/me?fields=id,email,cover,name,first_name,last_name,age_range,link,gender,locale,picture,timezone,updated_time,verified',
function (response) {
console.log('response');
console.log(response);
}
);