"Could not get GraphUser from Facebook Session" error when login through FacebookSDK

Hi,

I am using the loginWithFacebookSDK to allow users to login to my Android app. When the user logs in for the first time, there is no issue at all. Logs in perfectly and stays logged in. But once I Logout and try to login again, I get this error which says “Could not get GraphUser from Facebook session”. My code is as follows

final View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Map<String, String> facebookFieldsMappings = new HashMap<>();
facebookFieldsMappings.put( “email”, “email” );
facebookFieldsMappings.put( “first_name”, “fb_first_name”);
facebookFieldsMappings.put( “last_name”, “fb_last_name”);
facebookFieldsMappings.put( “gender”, “fb_gender” );

    List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
    permissions.add("email");
    permissions.add("public_profile");

    Backendless.UserService.loginWithFacebookSdk(LoginActivity.this, facebookFieldsMappings, permissions, callbackManager, new AsyncCallback&lt;BackendlessUser&gt;() {
        @Override
        public void handleResponse(BackendlessUser backendlessUser) {
            // user logged in successfully
            Log.i("Success into facebook", backendlessUser.getEmail());
            mUser = backendlessUser;
            startIntent();
        }

        @Override
        public void handleFault(BackendlessFault backendlessFault) {
            System.err.println("Error - " + backendlessFault);
        }
    });

}

};
facebookLoginButton.setOnClickListener(listener);

However, using AccessToken Tracker of Facebook, I am able to retrieve the current Access token, and subsequently the
user’s name, id etc using GraphRequest.

Kindly help me in this regard. When I use easy facebook login, everything works, but this error occurs only on SDK version of login

Thanks

Hi, any help is appreciated. This has been bothering me for nearly a week now. Thanks

I had the same issue and I solved it adding the Android Application into the App Dashboard at Facebook.

To do that I went to the App Dashboard, the url is something like:
https://developers.facebook.com/apps/app_number/settings/ then i click on settings on the left and then click on Add Platform, choose android and fill the form.

I hope it’s useful for you.

Hi Roberto,

Thanks for the reply. I had already added the platform and now revisited it to check if the details are correct. My Class name given there is the default Activity name in my app. Everything is correct, but nothing works,

To make sure it is not to do with anyother component of my app, I created a new app and added nothing but facebook login as described by Backendless and Facebook. Same error. First time logs in corretcly. Second time onwards, it shows the same error.

The Easy facebook login works fine though, I don’t know why this does not work. So frustrating

Any help is appreciated

please send us your example on support@backendless.com

Hi Sergey,

I’ve sent a mail with the subject line similar to the title of this issue. Any help is appreciated.

Thanks

Hi,

Any update on this issue is appreciated.

Thanks

Any updates on this topic? i’m having the same problem right now.

Hi, Michael! Did you try our sample for LoginWithFacebookSDK?

https://github.com/Backendless/Android-SDK/tree/master/samples/UserService/FacebookSDKSamples

Hi Anatolii,

Your sample does not work too. I already sent my code to you through mail but haven’t gotten a reply (it has been 2 months). You sample app too has the same issue. I am surprised that nobody else has come forward to address this issue. If you can help me sort this out, it will be much better, as I don’t want to switch service just because I am not able to let users log in through facebook this way.

Regards
Arun

Hi Anatolii, I took my code from your sample. I looked into this problem further, and i have found one “funny” fact, when the device has no Facebook application the login seems to work just fine (i get a pop up window browser kindof and i can log in to my facebook account), on the other hand when i have a facebook application installed on my phone i can’t seem to log in with this method.
Backendless.UserService.loginWithFacebookSdk(this, facebookFieldMappings, permissions, callbackManager,
new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser backendlessUser) {
// user logged in successfully
}

@Override
public void handleFault(BackendlessFault backendlessFault) {
    // failed to log in
}

});

My guess is that there is something wrong with the Facebook SDK, or with the integration between the method and the Facebook SDK. The problem is i have more important bugs to fix at the moment, and i can’t look into this problem right now. In two days i think im gonna be able to work on it again, I’ll give you guys my feedaback.
Kind Regards,
Michael

Hi Michael,

We would appreciate if you could clearly describe the misbehaviour in the separate support topic. A code sample which we could run and reproduce the problem would be just perfect.

Hi Sergey,

I have attached a sample file - this has the same problem - Try it in your phone / emulator with facebook app preinstalled. It lets you log in the first time properly without any issue. If you logout of the app once and try logging in again, you get this error (Could not get Graph User from facebook session).

Can you have a look at this and get back so we can try solve this issue at the earliest? Thanks

Testapp.zip (26.99MB)

Unfortunately, I couldn’t reproduce it even with your app. I logged in, closed the app, then opened it again, saw the “You have already authorized …” message from Facebook and no error after that.

Ok im glad to announce that the problem is solved. For some reason if you follow the fb instructions to get a hash key for your android app you will get a one time hash key.

The right way to get the key is to past this code in any activity :

try {
PackageInfo info = getPackageManager().getPackageInfo(
“com.example.packagename”,
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance(“SHA”);
md.update(signature.toByteArray());
Log.d(“KeyHash:”, Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
e.printStackTrace();

} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
you can delete this code after you get the key from android monitor console. Update your key in the fb developer console and everything should be fine. At least in my case it was.
Hope you fine this helpfull.
Kind regards.