Thursday, April 3, 2014

Unity3D and facebook SDK login problem for android devices

So you created you Unity3D game, integrated with Facebook's shining plugin. But still you are not able to login right? Infact nothing happens when you click that login button.

here is the problem: key_store hash!

I know you installed openssl and put your key on your facebook page.

well the thing is your key_hash is not valid.

When you debug your application with adb logcat, you can see a row like this:

"W/fb4a(:<default>):BlueServiceQueue(19773): com.facebook.http.protocol.ApiException: Key hash ******* does not match any stored key hashes."

**** = a key hash which I masked for privacy reasons.

well use that key_hash on your facebook app page.

go https://developers.facebook.com/apps  and select your aplication, choose "Settings" from the menu on the left and write that key hash which you see on the adb logcat log on facebooks key hashes part.  Save and update facebook.

that is it.

If you dont know how to use adb log cat, read my article on this url:

---

Here is a quick how to use adb :

1) goto your sdk installation directory, (adt\sdk\platform-tools) and run this command:
adb logcat  > mylog.txt

this command will dump all logs to mylog.txt file. open that file and search for key hash keyword on the log.  To Search adn solve your login problem ,  do these:

i) open mylog.txt in your favourite text editor.
ii) search this word: ApiException
you will find some rows like this: 

W/fb4a(:<default>):BlueServiceQueue(26232): com.facebook.http.protocol.ApiException: [code] 404 [message]: Key hash yd13SdjudjDdwdwedWsdddcwVJW  does not match any stored key hashes. [extra]: null
( there you will find your real key hash: yd13SdjudjDdwdwedWsdddcwVJW) 

iii) put  an extra = sign at the end and key hash become like this: yd13SdjudjDdwdwedWsdddcwVJW=

iv) copy paste this keyhash into your facebook developer page. all your facebook sdk login problems will be gone. 
 ----

These steps also valid for macbook - macos unity - fcebook login sdk problems. 


There you will find your real key hash. Use this key hash on facebook key hashes form. The one unity creates is false.


------

btw Isearched a lot on internet and find these solutions below. But I did not try any of them. so you can also try these ones:

1) Some people say openssl which you install really matters and recommends to install a spesific version. Maybe with that openssl unity panel will give you the real key hash, I did not try try that.

2) Also create two key hashes one for debug one for release with these commands:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

keytool -exportcert -alias yourappreleasekeyalias -keystore ~/.your/path/release.keystore | openssl sha1 -binary | openssl base64

some urls you may invetigate further:
http://stackoverflow.com/questions/13894006/android-facebook-sdk-3-0-gives-remote-app-id-does-not-match-stored-id-while-lo/16059786#16059786

http://answers.unity3d.com/questions/576088/facebook-sdk-simple-login.html

http://stackoverflow.com/questions/13894006/android-facebook-sdk-3-0-gives-remote-app-id-does-not-match-stored-id-while-lo

http://stackoverflow.com/questions/19051361/facebook-unity-sdk-on-android-login-fails-when-fb-app-installed/19091114#19091114

http://stackoverflow.com/tags/facebook-unity-sdk/hot

http://answers.unity3d.com/questions/609810/using-facebook-api-with-android-says-login-is-canc.html


No comments:

Post a Comment