Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook SDK login issue with parse sdk

I have a weird problem when logging using the LoginManager class. I am calling LoginManager.getInstance().logInWithReadPermissions(..) from a fragment to login with the required permissions.

I've debugged as far as I can and I found that the callback request code which returns to the onActivityResult of the parent activity of this fragment is wrong. The following piece of code is from the LoginManager class which registers the callback for login with some request code.

...
CallbackManagerImpl.registerStaticCallback(
              CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(),
              new CallbackManagerImpl.Callback() {
                 @Override
                 public boolean onActivityResult(int resultCode, Intent data) {
                   return LoginManager.this.onActivityResult(resultCode, data);
                 }
              }
      );
...

But when it calls the onActivityResult of the activity it's not the CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode() but something else it's like double. For example when i tried to debug and check the values it was something like this:

CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode() = 64206

requestCode received in Activity class = 129742

and now because of this when callbackManager tries to call the onActivityResult like

callbackManager.onActivityResult(requestCode, resultCode, data);

with this requestCode it doesn't find the logincallback from the map to go ahead and it stops right there. I don't know why it's happening as i am using ParseFacebookSDK and when i do login with ParseFacebookUtils.logInWithReadPermissionsInBackground(..) it works perfectly. Following is the gradle dependencies.

...
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile('com.parse:parse-android:1.13.0') {
        exclude group: 'com.parse.bolts',
                module: 'bolts-tasks'
    }
compile 'com.parse:parsefacebookutils-v4-android:1.10.3@aar'
...

If you can help, would be greatly appreciated. Thanks.

UPDATE:

It worked for me when i tried facebook login from parent activity instead of fragment, it returned the correct request code in onActivityResult of activity this time and it simply worked. This has resolved my problem but still want to understand the problem with fragment here, so if you know please share your thoughts. Thanks.

like image 205
KunalK Avatar asked Jan 06 '17 11:01

KunalK


1 Answers

Trying to call ParseFacebookUtils.logInWithReadPermissionsInBackground while your user is already logged is not correct, and probably that's why you don't get the callback.

The correct function to call if your user is already logged in, but not linked to Facebook, is ParseFacebookUtils.linkWithReadPermissionsInBackground, meaning that you want to link the user to facebook, not log in to your app (as he is already logged in). Take a look in the docs for that.

like image 118
Natan R. Avatar answered Sep 27 '22 18:09

Natan R.