Reputation: 1250
I want to retrieve a email address of a user by calling facebook api. I am using
FB.api('/me?fields=email', function(response) {
var txt="Email:"+response.email;
var element=document.getElementById("email").innerHTML=txt;
});
code to retrieve a email address.
I have asked for email permission during login as follows:-
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
FB.login({scope: 'email'});
} else {
FB.login({scope: 'email'});
}
});
};
Still when I print email id it shows "undefined".
Upvotes: 0
Views: 168
Reputation: 1250
Ok, I have got answer to my problem. If you are using Facebook's Button code then You have to add extra permissions as an array. What i was doing was that calling the Login Function manually with permissions but forgot to add permissions as a scope in button code.
<div class="fb-login-button" data-max-rows="5" data-size="xlarge" data-show-faces="true" scope=['email'] data-auto-logout-link="true"></div>
Upvotes: 1