javaandroidfacebook-loginfacebook-android-sdk

Android CallbackManager call back stopped working after upgrading to Facebook SDK 12.0.0 (Or 13)


I have an Android app that does login via Facebook. Everything was working when I was on Facebook SDK

implementation 'com.facebook.android:facebook-android-sdk:11.1.1'

However, recently I noticed in my Gradle file that there is an update available for Facebook SDK, so I updated it to

implementation 'com.facebook.android:facebook-android-sdk:13.0.0'

And then the problem happens.

Before I have my code setup like the following:

private void facebookSignInSetup() {
    //Facebook login setup
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                  ....
                }

And in my Activity class I have the following code:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        callbackManager.onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
        ......
    }

When I was on Facebook SDK 11.1.1, after user login via Facebook, method: onActivityResult is fired then FacebookCallback registered is fired.

After upgrading to Facebook SDK 13.0.0 (I tried 12.0.0 also having the same problem), after the user login to Facebook, onActivityResult is called, however, FacebookCallback is not called.

Hence my login process is broken.

Anyone has the same problem and is the resolution?


Solution

  • According to the post: How to use Facebook Sign in CallbackManager with onActivityResult deprecated?

    It seems after Facebook Android SDK 12, the approach of using

    onActivityResult

    is deprecated. And as of today, I am posting this question (2/March/2022), Facebook official developer document: https://developers.facebook.com/docs/facebook-login/android/#9--register-a-callback is still telling everyone the old way of doing Facebook login.

    I hope this post could help others facing the same problem.

    The following are the solution

    Sample code: https://github.com/facebook/facebook-android-sdk/blob/main/samples/FBLoginSample/src/main/java/com/facebook/fbloginsample/FacebookLoginActivity.java

    Solution:

    1. Remove

      callbackManager.onActivityResult(requestCode, resultCode, data); from onActivityResult

    2. Setup your Facebook button with permission

      LoginButton mLoginButton = findViewById(R.id.login_button); mLoginButton.setPermissions(Arrays.asList("public_profile", "email"));

    3. Replace LoginManager with your LoginButton instance. Change:

      LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback() { Change to:

      mLoginButton.registerCallback(callbackManager, new FacebookCallback() {