I am playing around with Google Plus Authentication and Firebase.
I am working through the basic auth example with Android at the moment. The basic authentication part is working fine with the code on github, and it works as it should. https://github.com/firebase/firebase-login-demo-android
The problem now arises when I am trying to fetch the email address, for some reason it doesn't seem to exist in the authData object.
From the Firebase documentation on Google authentication:
getProviderData().get("email") - The Google user's primary email address as listed on their profile. Returned only if a valid email address is available, and the Google
If I add a textview in activity_main.xml ..... .....
Then in my code MainActivity.java:
private void setAuthenticatedUser(AuthData authData) {
if (authData != null) {
/* Hide all the login buttons */
......
mLoggedInStatusTextView.setVisibility(View.VISIBLE);
mEmailTextView = (TextView) findViewById(R.id.email_textView);
mEmailTextView.setText(authData.getProviderData().get("email").toString());
mEmailTextView.setVisibility(View.VISIBLE);
......
}
I get an error: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
Additionally, in Android Studion with Debug on, when I look into the authData object, email is not set, but other values are - auth, provider, providerData, token, uid, expires, etc...
Everything seems to be working great except fetching the email address. I'm not sure if any addiontial permissions are needed. In my AndroidManifest.xml file I have the following:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
From what I've read, the GET_ACCOUNTS permission SHOULD be enough. Any ideas on why Firebase can't seem to fetch it?
EDIT: Additionally, I am able to save my user data to Firebase https://www.firebase.com/docs/android/guide/user-auth.html#section-storing
if(authData.getProviderData().containsKey("email")) {
map.put("displayName", authData.getProviderData().get("email").toString());
}
Then this email value is always empty, so it's not retrieving the email from Google Plus at all.