Search code examples
androidfirebaseauthenticationfirebase-authenticationfacebook-android-sdk

Firebase AuthUI - Fetch additional User Information from Facebook Provider


I'm trying to get the requested information from Facebook Provider of Firebase AuthUI.

I didn't find any method to get this data. When I debug that step, I can see the requested information in the attribute "zzdd" as JSON like.

How can I get this data?

Request birthday and gender information from user:

new AuthUI.IdpConfig.FacebookBuilder()
  .setPermissions( Arrays.asList( "user_birthday", "user_gender" ) )
  .build() );

Fetch data from provider

mUser = FirebaseAuth.getInstance().getCurrentUser();
for( UserInfo user : mUser.getProviderData() ) { }

Debbuger - user - zzdd attribute

{"birthday":"08/05/1995","updated_time":"2018-05-04T21:28:53+0000","gender":"male",...}

Firebase AuthUI Version: 3.3.1


Solution

  • I found the solution.

    To get additional information by Firebase Auth you must get by SDK providers, like Facebook as code below:

    Get data from Facebook SDK on Login Success with Firebase AuthUI:

                        GraphRequest request = GraphRequest.newMeRequest(
                            AccessToken.getCurrentAccessToken(),
                            new GraphRequest.GraphJSONObjectCallback() {
                                @Override
                                public void onCompleted( JSONObject jsonObject, GraphResponse response ) {
                                    // Application code
                                    try {
                                        String birthday = jsonObject.getString( "birthday" );
                                        String gender = jsonObject.getString( "gender" );
                                    } catch( JSONException e ) {
                                        e.printStackTrace();
                                    }
                                }
                            } );
                    Bundle parameters = new Bundle();
                    parameters.putString( "fields", "birthday,gender" );
                    request.setParameters( parameters );
                    request.executeAsync();