Not able to login in my app using fb-unity-sdk | OnLoginComplete({"cancelled":true}) | API Exception

2.8k Views Asked by At

I am using the latest facebook sdk for unity (Package 4.3.6) for my Unity project. Whenever I try to login, this is what I get in the verbose from the LogCat.

12-09 22:54:05.911: V/FBUnitySDK(19876): sending to Unity OnLoginComplete({"cancelled":true})

And when I tried to deep dive in the logcat, these are the errors I am got.

12-09 22:53:52.298: E/fb4a(:):VaultDeviceSetup(19890): com.facebook.http.protocol.ApiException: Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons. 12-09 22:53:52.298: E/fb4a(:):VaultDeviceSetup(19890): at com.facebook.http.protocol.ApiResponseChecker.b(ApiResponseChecker.java:103) 12-09 22:53:52.298: E/fb4a(:):VaultDeviceSetup(19890): at com.facebook.http.protocol.ApiResponseChecker.a(ApiResponseChecker.java:136) 12-09 22:53:52.298: E/fb4a(:):VaultDeviceSetup(19890): at com.facebook.http.protocol.StringResponseHandler.a(StringResponseHandler.java:31) 12-09 22:53:52.298: E/fb4a(:):VaultDeviceSetup(19890): at com.facebook.http.protocol.ApiResponseHandler.b(ApiResponseHandler.java:89)

Also facebook settings wasn't able to find my debug.keystore and it was showing me an warming of missing debug.keystore. I already had the debug.keystore file in the .android folder but It was still not detecting it. So i put my keyhash directly into the FacebookAndroidUtil.cs file like this.

private static string debugKeyHash="MY_KEY_HASH";

And I put the same key hash in my facebook app setting too. So I am not sure what is causing the login issue. Whether it is a key hash issue or an access token issue as shown in the logs. I am stuck at it since 2 days. :(

2

There are 2 best solutions below

2
On

To be able to log in using Android you need to make sure that ALL of the 'Basic' app settings of your 'Native Android App' are filled in correctly on Facebook. You can find these settings on the following location.

http://developers.facebook.com/apps/YOUR_FB_APP/summary

The settings you need to fill in can be found in the unity editor (Facebook > Edit Settings > Android Build Facebook Settings)
If your 'Debug Android Key Hash' is missing and there's an error message saying 'Your android debug keystore file is missing! You can create new one by creating and building empty Android project in Eclipse.' even though you are sure that the file exists, it is probably because your Unity project is not located on your Windows installation drive.

To resolve that you'll need to alter some code from the original Facebook plugin (my version was 4.3.4).
On line 62 of YOUR_UNITY_PROJECT\Assets\Facebook\Editor\android\FacebookAndroidUtil.cs replace

System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" : 

with

System.Environment.GetEnvironmentVariable("HOMEDRIVE") + System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" : 

Also make sure that your PATH environment variable of Windows contains a location to your 'keytool' which comes with any Java installation. For example:

C:\Program Files\Java\jre6\bin

If you had to change the environment variable, be sure to restart Unity.

Your can now use the 'Android Build Facebook Settings' to fill in the 'Native Android App' settings on Facebook.

Hope this helps!

0
On

By replacing

System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" :

by

System.Environment.GetEnvironmentVariable("HOMEDRIVE") + System.Environment.GetEnvironmentVariable("HOMEPATH") + @"\.android\debug.keystore" :

made it work for me in Windows 8