Reputation: 58
I'm using the code that is on the FB Login documentation for Javascript. But it doesn't fetch user's email adresss. It was working with older versions...but it doesnt with the version of my app (v2.4). I'm also using the facebook login button.
Here's what I've got:
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;
});
}
And this is the button part:
<fb:login-button scope="email,user_birthday,user_about_me" autologoutlink="true" onlogin="checkLoginState();">
</fb:login-button>
Upvotes: 1
Views: 1533
Reputation: 73984
FB.api('/me?fields=name,email', function(response) {...
Search for "Declarative Fields" in the changelog: https://developers.facebook.com/docs/apps/changelog#v2_4
Upvotes: 2