Steven Montero Cordero Steven Montero Cordero - 5 months ago 34
Javascript Question

Using facebook API javascript getting email

I have this method and I want to get the email of a person and Send email=undefined.

First Try:

function testAPI() {
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.email + '.');
alert('Good to see you, ' + response.email + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope:'email'});


I was searching and i found that I have to use {scope:image} and if i put it, dont show me the alert

Answer

Your syntax is wrong, that's the correct one:

function testAPI() {
    FB.login(
        function(response) {
            if (response.authResponse) {
               console.log('Welcome!  Fetching your information.... ');
               FB.api('/me', function(response) {
                   console.log('Good to see you, ' + response.email + '.');
                   alert('Good to see you, ' + response.email + '.');
               });
            } else {
                console.log('User cancelled login or did not fully authorize.');
            }
        },
        {scope:'email'}
        );
}

where the {scope:'email'} is inside the ) as second argument of the FB.login