0

I'm pretty new with Firebase and Facebook logins, so I followed many tutorials on how to login using Facebook on my real time database. The problem is that when you click the LoginButton an activity seems to start, but after that it immediately closes. I've implemented Google login and it all works fine, I really can't find the problem.

Here's how I've done it

mCallbackManager = CallbackManager.Factory.create();
    facebookButton.setReadPermissions("email", "public_profile");
    facebookButton.setFragment(this);
    LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG,"XD1");
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "cancel");
        }

        @Override
        public void onError(FacebookException error) {
            Log.e(TAG, "error connecting to fb", error);
        }
    });

private void handleFacebookAccessToken(AccessToken token){
    Log.d(TAG, "handleFacebookAccessToken:" + token);

    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        LoginManager.getInstance().logInWithReadPermissions(getActivity(), Arrays.asList("public_profile"));
                        getFragmentManager().beginTransaction().replace(R.id.frameLayout, PhoneFragment.newInstance(mAuth.getCurrentUser().getUid())).commit();
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w("errore", "signInWithCredential:failure", task.getException());
                        Toast.makeText(getContext(), "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode==REQUEST_GOOGLE) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG, "onResult di google");
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try{
            GoogleSignInAccount account = task.getResult(ApiException.class);
            firebaseAuthWithGoogle(account);
        } catch (ApiException e){
            Log.e("errore", "errore, avvisare l'utente");
        }
    } else {
        Log.d(TAG, "onActivityResult di facebook richiamato");
        // Pass the activity result back to the Facebook SDK
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
    }
}

The error the logcat shows me is SERVER_ERROR: [code] 1675030 [message]: Error performing query. [extra]: Errors while executing operation "ProxyAuthAppLoginStartQuery": At Query.proxy_auth_app_login_start: Field implementation threw an exception. Check your server logs for more information.

I thought it was because of test users but adding them changed nothing

Donax
  • 5
  • 4

2 Answers2

-1

Follow the tutorial of Facebook of adding sdk to your app. Most likely you sdk is not properly setup so when you start Facebook auth the sdk fails due to client id missing. Also you have to setup Facebook in firebase project console so that Firebase can complete the auth and get necessary information

Umar Hussain
  • 3,461
  • 1
  • 16
  • 38
-1

The problem was the tag meta data in the manifest. I couldn't add the meta data in application as CacheMeOutside answers here SERVER_ERROR: [code] 1675030 [message]: Error performing query because that tag is already in the merged manifest (I think because of Firebase), so all I had to do was changing in my string resource file the string name "facebook_app_id" to "facebook_application_id" and it all worked fine. Hope this might help someone

Donax
  • 5
  • 4