Facebook Unity SDK on Android - Login fails when FB App installed

Brizee picture Brizee · Sep 27, 2013 · Viewed 13.4k times · Source

I appear to be having the same issue as discussed in this question: Facebook SDK for Unity on Android - Trouble about callback from FB.Login

On Android when the regular Facebook app is installed, calls to FB.Login() using the Unity SDK prompt the user to accept permissions for the app and when the app is approved the callback is fired with: FBResult.Text

{"is_logged_in":false,"user_id":"","access_token":""}

FBResult.Error

null

When the Facebook app is installed the web flow is used and works fine, I have however tried this with v4.2.4 and v4.2.2 of the Unity SDK.

Any other advice on getting this resolved?

EDIT: Should also note, I've tried this on 2 different devices (Galaxy Note 10.1 and Nexus 7)

Thanks in advance!


A note for 2014. In some cases the problem is very simply that you've forgotten the settings on developers.facebook. Brian explains it here with images: http://answers.unity3d.com/questions/543540/facebook-sdk-v424-android-login-not-working.html Confusingly it WILL WORK (!) on devices WITHOUT the fb app, if you have completely forgotten the settings. As to the actual problem, fortunately there is a solution even if you are using Unity on Mac and it is simple: http://answers.unity3d.com/questions/609810/using-facebook-api-with-android-says-login-is-canc.html

Answer

Brizee picture Brizee · Sep 30, 2013

Ach feel so silly, eventually managed to solve it myself, by deploying to an intermediary Google Android Project, I was able to use logcat to obtain a more useful error messsage:

remote_app_id does not match stored id

From there I found this topic relating to the standard Android SDK: Android Facebook SDK 3.0 gives "remote_app_id does not match stored id" while logging in

And finally solved the problem by replacing the Key Hash with the one obtained by this code snippet

try {
PackageInfo info = getPackageManager().getPackageInfo(
      "com.facebook.samples.loginhowto", 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) {
} catch (NoSuchAlgorithmException e) {
}

Replacing com.facebook.samples.loginhowto with your own package name of course

Source: https://stackoverflow.com/a/14421260/2823496

It seems getting the correct keyhash, via command line or through Unity depends on having the right version of openssl installed (and stored in PATH) but no idea what version that is. (tried the one in linked answer) So heads up to anyone else struggling with this.


Note - it's almost impossible to do this if you're using Mac for Unity development. Here's the fortunately simple solution in that case http://answers.unity3d.com/questions/609810/using-facebook-api-with-android-says-login-is-canc.html