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
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
Share Improve this question edited Jul 10, 2015 at 1:27 Steven Montero Cordero asked Jul 10, 2015 at 0:47 Steven Montero CorderoSteven Montero Cordero 611 gold badge2 silver badges8 bronze badges3 Answers
Reset to default 24Replacing this
FB.api('/me', function(response) {
// ...
with this
FB.api('/me?fields=id,name,email,permissions', function(response) {
console.log(response.name);
console.log(response.email);
// ...
I can get the user's email.
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
Or use
FB.init('/me', {"fields":"id,name,email,first_name,last_name"}, function(response){
console.log(response.email);
});