9

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

Community
  • 1
  • 1
Brizee
  • 190
  • 1
  • 2
  • 15
  • Would it be possible for you to send us your project so we can try to debug it? Use unity-sdk@fb.com if you want to send us a link for download (or just attach it). Thanks for the detailed report! – aaron Sep 30 '13 at 06:21
  • 1
    Sorry had it fixed already but stackoverflow didn't want me answering my own question quite yet. Perhaps there would be a more intuitive way to return that error to Unity SDK though? :) – Brizee Sep 30 '13 at 09:47
  • @BrianBeacom Hi I am facing the same issue with the plugin. Even entered the hashkey that comes in the log into the developer console. BUT I am very much unsure on how to do this. Some topics suggested--- --> The FB app should be updated to the latest one. --> The hashkey generated in the logcat should be entered into the dev console. --> We have to create a keystore(our own) and put the generated hashkey into the dashboard. I did all the steps and still I'm stuck into the same problem. Perhaps you can guide me into it. – Siddharth-Verma Jan 19 '14 at 18:58
  • @user1683989 Hey so you'll wanna put the hashkey generated in logcat into your Facebook Dev Dash, go [here](https://developers.facebook.com/apps/) pick your app then either Settings or Edit depending on which version of FB you get, from there you need to find the list of platforms and if it's not there Add Android and pop your hashkey in the Key Hashes section under it. – Brizee Jan 20 '14 at 15:34
  • @user1683989 The version of Facebook installed (or if it's installed at all) shouldn't matter as the keyhash is generated by Android not Facebook, Facebook just uses it for authenticity. Keystores and such don't matter and you won't need to put it anywhere in Unity. As long as you don't change the bundle identifier you should be fine. – Brizee Jan 20 '14 at 15:37
  • @BrianBeacom Hi I already did that earlier (I correctly generated the keyhash from the keystore, entered it) but the problem Now I am facing is that THE FACEBOOK SDK v4.2.4 Works Well with unity 4.2.x BUT NOT WITH Unity 4.3.x. Earlier I was testing it in unity 4.3, but when i downgraded unity to 4.2, there were no issues. So the Real Issue is HOW TO GET IT WORKING in Unity4.3(I tried with 4.3.0,.1,.2 and .3 but still no result as in when you log in, it asks for a permission and then goes back to the previous screen returning isLogged in FALSE, unity4.3). – Siddharth-Verma Jan 21 '14 at 05:28
  • @user1683989 Ah I see, unfortunately I've not encountered that myself so you might want to make a new question for it. I know aaron is generally quite quick to help, apart from that all I can suggest is plug it in into logcat and see if the underlying Android SDK is giving an error message (as the Unity plugin just seems to hook into Android/iOS plugin) and you can also check if it works without the FB app installed as the web flow doesn't seem to need the correct key hash. Both may narrow down the possibilities at least. – Brizee Jan 21 '14 at 10:23
  • @BrianBeacom here you go. Check at this link, it will give you a clear idea. http://stackoverflow.com/questions/21251565/facebook-android-sdk-4-2-4-cant-log-in-and-islogged-returns-false-with-unity-4-3 – Siddharth-Verma Jan 21 '14 at 15:46

2 Answers2

5

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

Community
  • 1
  • 1
Brizee
  • 190
  • 1
  • 2
  • 15
  • Could you tell me when did you put this code snippet? I'm trying to put it on the classes generated by unity (UnityPlayerActivity, UnityPlayerNativeActivity, UnityPlayerProxyActivity) but nothing is being logged. – Álvaro Oct 10 '13 at 13:27
  • 1
    @Álvaro Ah it's a bit tricky, part of how the Facebook plugin works is it to create the FBUnityPlayerActivity and run requests through this. So you'll need to change the manifest.xml so that: is under your UnityPlayerActivity or, I imagine you can call it in some other way like doing (off the top of my head) adb shell am start com.company.appname/.UnityPlayerActivity – Brizee Oct 10 '13 at 17:22
  • Bah, Markdown wasn't being my friend sorry, hope you can get the code snippets from that. :) – Brizee Oct 10 '13 at 17:30
0

I had a same error. And i have remove facebook app. My app is working fine


MORE ON THAT: https://stackoverflow.com/a/23446140/294884

Community
  • 1
  • 1
Long Pham
  • 7,464
  • 3
  • 29
  • 40
  • Congrats my friend, you pretty much repeated the question :) Nah, if it was just for my use that'd be fine, unfortunately, I couldn't afford to limit the market for my app to people who don't have Facebook installed. See the accepted answer above if you want to resolve it yourself. :) – Brizee Oct 29 '13 at 10:54
  • This problem i had to solved when I get exact key hash and add it to Facebook/app on developer facebook – Long Pham Oct 30 '13 at 13:07
  • @longpham Hi I am facing the same issue with the plugin. Even entered the hashkey that comes in the log into the developer console. BUT I am very much unsure on how to do this. Can you help me into this. I shall be glad Thanks in Advance. – Siddharth-Verma Jan 19 '14 at 19:02
  • @user1683989 .Send to me your email address. I will send u a android project. This project will get a keyhash and you put on to developer console. – Long Pham Mar 02 '14 at 17:03