Using Facebook API with android, says login is cancelled by Player.

I’m trying to follow this example : Android - Unity SDK - Documentation - Meta for Developers

I am using Unity 4.3.1f1.

ADT adt-bundle-windows-x86_64-20131030

Facebook unity API 4.3.6

I generated my debug keystore using :

keytool -exportcert -alias androiddebugkey -keystore “C:\Users\Rafael.android\debug.keystore” | openssl sha1 -binary | openssl base64

Which worked OK, it gave me a proper key hash, on the Facebook settings, it shows the same keyhash, on the android build settings I selected that same debug.keystore and entered the proper password and also populated the app page on facebook with everything correctly, the package name, the class, and the key hash are all there.

However when running the example “InteractiveConsole” scene on my android the init works nicely but when I click login, it asks for permissions and I press OK, and it then says that “login was cancelled by the Player”.

I am at a complete loss on why that would happen, any ideas ?

So answering my own question, turns out the key hash was wrong, I modified the facebook API file AndroidFacebook.cs and made it log whatever key hash it was using by changing this method :

        public void OnLoginComplete(string message)
        {
            var parameters = (Dictionary<string, object>)MiniJSON.Json.Deserialize(message);

            if (parameters.ContainsKey("user_id"))
            {
                isLoggedIn = true;
                userId = (string)parameters["user_id"];
                accessToken = (string)parameters["access_token"];
            }

            if (parameters.ContainsKey("key_hash"))
            {
                keyHash = (string)parameters["key_hash"];
				Debug.Log("proper keyhash : " + keyHash);
            }

            OnAuthResponse(new FBResult(message));
        }

And the logged keyhash was different from what every other method was giving me, including the API own informed key, I added the proper key to the facebook page it everything is OK now.

Hi guys… Sorry to revive such an old thread but I found the actual reason for the different keystore value. It is using the keystore defined in your publish settings. You have to either define the debug.keystore file there or use something like the fix i wrote for the faceboook sdk below.

Facebook SDK Fix

I just make the facebook sdk use the defined PlayerSettings.Android keystore values. Hope this helps! Cheers! (Just update to version 6.0)

Good post. I would like to add one more solution for when it fails even though following all solutions posted here.
If the facebook app hasn’t been opened for public, then only development accounts can be log in to the facebook app.
I spent about 2 hours because of this reason.

to those who might need this its really useful and it works for me
I just copy this instruction from this link

so first things first,

  1. Download and install OpenSSL.
    Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

Win32 OpenSSL v#.#.# (not Light)

OR Win64 OpenSSL v#.#.# (not Light)

  1. Add the OpenSSL directory to your path.

Go to: Control Panel > System > Advanced system settings > Environment Variables

Select the Variable “Path” in the “System variables” window and click Edit.

  1. Add the path to your OpenSSL bin folder to the end of the “Variable value” text. e.g. I added “;C:\Program Files\OpenSSL-Win64\bin” to the end of the value text.

Restart Unity3D.

take note do not forget to add semi-colon “;” before the C:/

  1. If you get the error in FacebookSettings “Keytool not found”, you need to add the JDK (Java Development Kit) bin directory to the Path variable value.

  2. Follow the same steps as before, but instead of the OpenSSL bin path, add the JDK bin path. e.g. I added “;C:\Program Files\Java\jdk1.7.0_45\bin” to the end of the value text.

Restart Unity3D.

I lost a lot of time because even with the correct hashkeys on developer configuration page, the login fails as above,
the problem was that the manifest is wrong, be careful with “regenerate manifest” button, it seems do not work well (at least for me).
To really re-generate the manifest I had to delete the manifest file and then click on regenerate it.

I hope this can help someone…

this is fully solved