Search code examples
ionic-frameworkfirebasefacebook-javascript-sdkcordova-facebook

Facebook4, Firebase, getting null email


I have an app built with ionic and firebase. I am using facebook4 cordova plug in to log in with facebook. When they log in, I get the name and email address of the user.. However in some devices, I am getting null emails addresses. When I go to auth section in firebase, I see their email address as (-) empty although the displayname is returning correct. Here is my code.

facebookConnectPlugin.login(['email', 'public_profile', 'user_friends'], //first argument is an array of scope permissions
    function (userData) {
    if (userData.authResponse) {
        facebookConnectPlugin.api('me/?fields=email,name,first_name,last_name', ["public_profile"],
            function (inforesult) {
                facebookConnectPlugin.getAccessToken(function (token) {
                    //alert("Token: " + token);
                    var credential = firebase.auth.FacebookAuthProvider.credential(token);
                    firebase.auth().signInWithCredential(credential).then(function (result) {

        alert(JSON.stringify(result)); // the email field is null.

        $scope.myprofile = result;

     }).catch(function (error) {
     // Handle Errors here.
      alert(error.message);
     / ...
       });
    });
  });

}
},
function (error) {
   alert(error);
    }
) 

Is there some kind of permissions I am missing?


Solution

  • They may not have their email approved, or they login with their mobile phones. You can´t be sure that every user got an email.