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?
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
Solution:
Remove
callbackManager.onActivityResult(requestCode, resultCode, data); from onActivityResult
Setup your Facebook button with permission
LoginButton mLoginButton = findViewById(R.id.login_button); mLoginButton.setPermissions(Arrays.asList("public_profile", "email"));
Replace LoginManager with your LoginButton instance. Change:
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback() { Change to:
mLoginButton.registerCallback(callbackManager, new FacebookCallback() {