How to save google and Facebook login integration into firebase Realtime database Android Studio Java

I know how to save basic (email and password) information into my Firebase database but I have no idea how to save google and Facebook login integration into my Firebase database Can someone explain me?

Code of Google Login Integration

 private void firebaseAuthWithGoogle (GoogleSignInAccount acct){


    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    fAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener() {
                @Override
                public void onComplete(@NonNull Task task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        FirebaseUser user = fAuth.getCurrentUser();
                        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                        startActivity(intent);
                        finish();


                    } else {
                        Toast.makeText(login.this, "Sorry auth failed.", Toast.LENGTH_SHORT).show();


                    }


                    // ...
                }
            });
}

Answer

For Facebook in registerCallback, you will get the user name,email and unique id by which you can check which user is this. Here is the example code:

loginButton.registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    progressDialog.show();
                    System.out.println("onSuccess");
                    GraphRequest request = GraphRequest.newMeRequest(
                            loginResult.getAccessToken(),
                            (object, response) -> {
                                try {
                                 String id = object.getString("id");
                               String  name = object.getString("name");
                                String  email = object.getString("email");
                                } catch (JSONException e) {
                                    Log.e("login", e.getMessage());

                                }
                                } else
                                    Toast.makeText(getApplicationContext(), "Fail to connect with Facebook, Try again later!", Toast.LENGTH_LONG).show();

                            });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields",
                            "id,name,email,gender, birthday");
                    request.setParameters(parameters);
                    request.executeAsync();

                }

                @Override
                public void onCancel() {

                }

                @Override
                public void onError(FacebookException error) {
                }
            });

And for Google in handleSignInResult, same you will personName, personEmail and personId by which you can check which user is this. Here is the example code:

 private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);
            if (account != null) {
                String personName = account.getDisplayName();
                String personEmail = account.getEmail();
                String personId = account.getId();
            }
        } catch (ApiException e) {
             
        }
    }

Note: Still if you don’t understand something let me know.