Unable To Fetch User's Gmail Email Address Through Firebase
Solution 1:
Not sure if it is your case, but one situation where you are able to get other fields but getEmail returns null is when in Firebase console > Authentication > Sign-In Methods you allow "creation of multiple accounts with the same email address"
There's a closed bug report already filed with google:
When you go to the Auth > Sign-In Methods page of your project in the Firebase console. do you have One account per email address on or off? If you allow multiple accounts per email address, you will get null for FirebaseUser.getEmail()
You have to use the option: "Prevent creation of multiple accounts with the same email address" or else FirebaseUser.getEmail() will return null
Ps: only users who first logged in after the option was turned off will be able to use this method successfully
Solution 2:
You'll need to also request the email
scope. From the Firebase documentation for Google authentication:
Here is an example of Google login where the session will expire upon browser shutdown and we also request the extended email permission:
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithOAuthPopup("google", function(error, authData) { /* Your Code */ }, {
remember: "sessionOnly",
scope: "email"
});
See also my answer there: Firebase and new Google Sign-In on Android
Post a Comment for "Unable To Fetch User's Gmail Email Address Through Firebase"