- Home /
Using Facebook API with android, says login is cancelled by Player.
I'm trying to follow this example : https://developers.facebook.com/docs/unity/getting-started/android/
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 ?
this is Amazing. Rafael == genius
This is the only crossplatform solution, I believe.....
You saved the day, Rafael. Incredible idea.
Answer by JustAnotherDude · Jan 05, 2014 at 06:57 PM
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.
Hey @RafaelF82 , Good to see this post. Am too running through this same error, but i couldn't able to fix it. I have changed the code how you mentioned above, but it's not entering into the
if (parameters.Contains$$anonymous$$ey("key_hash"))
{
}
so i couldnt able to get the proper key hash value. I created a $$anonymous$$eyhash through console with alias and keystore and pasted it into the application settings on facebook. no luck. can please help to figure out ?
I/Unity (26072): LoginCallBack : UI$$anonymous$$anager Text :{"is_logged_in":false,"user_id":"","access_token":""} Error : I/Unity (26072): I/Unity (26072): (Filename: ./Runtime/ExportGenerated/Android$$anonymous$$anaged/UnityEngineDebug.cpp Line: 54) I/Unity (26072): LoginCallBack : Login cancelled by Player : I/Unity (26072): I/Unity (26072): (Filename: ./Runtime/ExportGenerated/Android$$anonymous$$anaged/UnityEngineDebug.cpp Line: 54)
Hi @sriram90 - it works perfectly; you have to run it ON A DEVICE; ie build to your device and actually connect over wifi to FB. You will have to FIND A WAY to display the information on your device screen; for example you must have some sort of "user alert" system; use that. Or just literally email it to yourself, or bring it up in a text field -- anything you can to display it on the screen of your device!
NB: DO NOT REPLACE THE FUNCTION WITH THE ONE ABOVE ANY $$anonymous$$OR$$anonymous$$ There's extra code in the latest FB sdk that isn't in that function. Just insert the debug log line.
Seriously, do it this way, especially if you are adding FB to an existing published app. Dicking around with keystores is a fantastic way to lose the ability to update your app forever. This method worked first time (you just have to log the key out from a device).
my code does not reach to this point. I am a new indie developer. The code does not reach to the debug.log point. Any help??
From what I can tell you no longer need this trick. When Facebook fails the actual FB UI displays this token now. The only catch in my case was that the hash FB showed didn't include a trailing equal sign.
Answer by vfxjex · Jul 06, 2014 at 02:38 PM
to those who might need this its really useful and it works for me I just copy this instruction from this link http://answers.unity3d.com/questions/573199/debug-android-hash-key-facebook-sdk.html
so first things first,
1) Download and install OpenSSL. http://slproweb.com/products/Win32OpenSSL.html
Win32 OpenSSL v#.#.# (not Light)
OR Win64 OpenSSL v#.#.# (not Light)
2) 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.
3) 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:/
4) 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.
5) 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.
Good one - but this doesn't help on $$anonymous$$ac. Very reliable is simply to do what Rafael said, which is very easy, and then you get to see "the actual value, no matter what."
$$anonymous$$y Facebook SD$$anonymous$$ fix basically gets you the proper keyhash value within unity that the actual facebook sdk uses. (So that way you don't have to try to read print logs).
Answer by Kabe0 · May 22, 2014 at 08:23 AM
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.
I just make the facebook sdk use the defined PlayerSettings.Android keystore values. Hope this helps! Cheers! (Just update to version 6.0)
If only the Facebook engineers made as big an effort as you, man! thanks!
I love you man... ($$anonymous$$abe0)...
Thank you sooooo muchhhh..........
Answer by seno · Jul 09, 2014 at 07:08 AM
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.
Well I feel like an idiot! This was bugging me for like 2 hours before I found your solution. Went ahead and flipped the switch to make it public and now I'm golden. Thank you, seno!
Answer by youest · Jul 10, 2014 at 10:55 AM
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...