Problem logging into Android for Android Facebook using parse sdk

I have a strange problem when registering using the LoginManager class. I call LoginManager.getInstance().logInWithReadPermissions(..) from the login fragment with the necessary permissions.

I am debugging as much as I can, and found that the callback request code that returns to the onActivityResult parent activity of this fragment is incorrect. The following code fragment belongs to the LoginManager class, which registers a 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 onActivityResult activity, it is not CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode() , but something else, like a 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 class Activity = 129742

and now because of this, when callbackManager tries to call onActivityResult, for example

callbackManager.onActivityResult (requestCode, resultCode, data);

with this requestCode he does not find a logincallback from the map to go forward, and he stops right there. I don’t know why this happens when I use ParseFacebookSDK and when I log in using ParseFacebookUtils.logInWithReadPermissionsInBackground(..) , it works fine. Below are 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, we will be very grateful. Thanks.

UPDATE:

This worked for me when I tried logging into facebook from the parent activity instead of the fragment, this time returned the correct request code in the onActivityResult activity, and it just worked. This solved my problem, but still want to understand the problem with the fragment, so if you know, share your thoughts. Thanks.

+5
source share
2 answers

Trying to call ParseFacebookUtils.logInWithReadPermissionsInBackground while your user is already registered is incorrect, and probably why you did not receive the callback.

The correct function to call if your user is already logged in but not connected to Facebook is ParseFacebookUtils.linkWithReadPermissionsInBackground , which means that you want to connect the user to facebook and not log in to your application (since he is already registered in). Look in the docs for this.

+3
source

If you call LoginManager.getInstance().logInWithReadPermissions(..) from the fragment, then expect to get the correct request code in the onActivityResult fragment, and not in the onActivityResult action.

See here . Fragments have their own onActivityResult method. They should not be dependent on activity for this.

Is it not surprising that something that does not necessarily require an interface still provides this method on its own :)

+2
source

Source: https://habr.com/ru/post/1262418/


All Articles