3

I am using parse server as a backend in the app. I've the requirement to login with Facebook as a sign up option. For that I am using

compile 'com.parse:parsefacebookutils-v4-android:1.10.3@aar'

Using this latest Facebook sdk for Android

compile('com.facebook.android:facebook-android-sdk:4.26.0') {
        exclude group: 'com.parse.bolts',
                module: 'bolts-android'
    }

When login first time after installing the app with facebook it all works fine

private void loginWithFacebook(){
        ParseFacebookUtils.logInWithReadPermissionsInBackground(this, Arrays.asList("public_profile", "email", "user_friends"), new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException err) {
                //....
            }
        });
    }

I can have the access token with other information which i can use later on in the app for different purpose, but the problem starts when i logout using:

LoginManager.getInstance().logOut();

this function logs me out properly but after logging again with same Facebook account using same logic for login when i debug and tries to get the Access Token it's null which I am not able to understand why as it should work just fine.

The account that I am using to login is already a test account which works fine with the iOS version of the application with the same flow but not in Android.

Let me know if I am doing anything wrong.

halfer
  • 19,824
  • 17
  • 99
  • 186
KunalK
  • 1,904
  • 4
  • 22
  • 40
  • What about this?: [Facebook SDK 4 for Android - how to log out programmatically](https://stackoverflow.com/a/32476054/8398526) – rweisse Sep 19 '17 at 18:04
  • have also tried to completely decouple facebook from the app https://pastebin.com/TGeYv8BJ but it's not working. It asks me for granting the permissions to FB, but still the access token is null after login. – KunalK Sep 19 '17 at 18:15
  • What is the error that you're getting? – Rohan Stark Sep 23 '17 at 09:03
  • Thing is after logging out and relogin with read permission on 2nd attempt and so on with the same account the access token is null. not getting any error. There is a functionality to relogin in the app to access the publish permission before sharing the post which opens the facebook dialog but it says __"some permissions can not be provided and need to submit for login review."__ kind of message which should not i think because the account i am testing with is already an administrator account. – KunalK Sep 24 '17 at 07:18
  • are you asking for same permissions on second attempt – chandrakant sharma Sep 27 '17 at 08:41

1 Answers1

0

Try to log out using this method:

ParseUser.logOut()

public static void logOut()

Logs out the currently logged in user session. This will remove the session from disk, log out of linked services, and future calls to ParseUser.getCurrentUser() will return null. Typically, you should use ParseUser.logOutInBackground() instead of this, unless you are managing your own threading.

Note:: Any errors in the log out flow will be swallowed due to backward-compatibility reasons. Please use ParseUser.logOutInBackground() if you'd wish to handle them.

I think your issue occurs because you are directly using LoginManager.getInstance().logOut() method of Facebook SDK, but ParseFacebookUtils caches some info about previous login. Try to call:

ParseUser.getCurrentUser().logOut();

BTW, if you look into the code of LoginManager.getInstance().logOut(), you will see next:

/**
 * Logs out the user.
 */
public void logOut() {
    AccessToken.setCurrentAccessToken(null);
    Profile.setCurrentProfile(null);
    setExpressLoginStatus(false);
}

It sets Access Token to NULL.

Also people advise to remove next call from your app's Application class:

ParseUser.enableAutomaticUser();
Sheikh
  • 1,116
  • 6
  • 15
  • ParseUser.getCurrentUser().logOut(); it's not working – KunalK Sep 28 '17 at 16:26
  • @KunalK, if your code is not confidentional, then can you share it on gist? It would be great to see your Activity with login processing. Thanks! – Sheikh Sep 29 '17 at 06:35