How to fix Facebook SDK Android Login

I just spent the whole day trying to understand how make the facebook sdk works on my Android device.

So here is the solution for anybody in my same shoes:
Avoid the user generated key hash, it doesn’t work( at least for me and probably many other). Anyway it’s made just for debugging and it’s not explained how to use for release.

To generate the hash use this on Windows.

And this on Mac:

It will ask the password for the keystore, if you don’t know yours just create a new keystore.
The path after -keystore is the keystore you want to use, and the word after -alias is your release key, so you can use the same method when publishing.

Copy the hash that it will give you in the facebook app settings and you are done.

More details here(the facebook unity sdk guide is totally useless):

1 Like

Hello christian,
I already followed the sdk guide, but nothing has changed. Btw, the command for windows needs a fix (at least on windows 8 - 8.1):

if yuo dont put "C:" before %HOMEPATH% it doesn’t ask you for a password.

Anyway, tested on a LG P700 and a samsung galaxy wonder, login doesn’t work.

Adding c: was what I did in the editor script to make it work, but on the commandline I didn’t have that issue on Windows 7.
Are you sure the password you are using is correct? Did you try regenerating the debug.keystore from unity?

from https://developers.facebook.com/docs/android/getting-started/:

“You will be prompted for a password. This should be ‘android’ without quotes.”

anyway, how do you regenerate the debug.keystore from unity?

On the player settings where you can set android specific settings like icons, there are two buttons, Use existing keystore, and create new keystore.
Try creating a new one, I didn’t test with the existing one, it could be the password isn’t really android.

Tried using both C:%HOMEPATH%.android\debug.keystore and a new one.
On a samsung galaxy (with facebook app installed) after clicking login, it ask for permissions (faceboook_test wants to access bla bla). Clicked ok, it return to the app page with login false.
On a Android 4.2.2 emulator (without facebook app installed) clicking on login crashes the app.

UPDATE: it seems that there is a weird error in the permission dialog: even if i press “OK” it comes back as cancel was pressed (in the log it appears: “login cancelled by player”).

I had the same issue until I properly configured it. Login cancelled by user is because of the hash.
Did you copy the hash generated by the command in the facebook app settings?

I generated a new one and overwritten the existing one at the HOMEPATH location using android as password, then generated the hash with the command line and copied it in the facebook dev center.

Battling with the same issue i think.
Did you notice that things work differently depending on whether you have the native android Facebook app (“FB app” from now on) installed on your device (or maybe that’s common knowledge but just not mentioned on this thread :stuck_out_tongue: )? For me the login works if i don’t have the native FB app installed.
Maybe that’s the problem “newlife” is having too.

I have an old, already released app, into which i’m trying to implement FB login. I regenerated the hash with my “release” keystore and openssl.

The problem is that I can’t perform the “first time flow” if I have the native FB app installed. Everything works perfectly if I log into my game without the FB app installed for the first time (so that FB SDK brings up the browser for logging in, instead of the FB app). After one successful login, I can install the FB app on my device and still my game continues to log in without problems.
With the native FB app login screen, my game doesn’t seem to be able to get the permissions right.

I guess i gotta try to regenerate the hashes again in case i made a mistake or something. Otherwise this is getting really frustrating.

EDIT ^^ posted from my other account accidentally

OK so the hashes surely aren’t the problem for me.
In Eclipse’s LogCat i’m able to see the calls and if I intentionally screw up the login call, i can clearly see the error messages now.

With my original code the login call goes through ok but it just doesn’t seem to return the FBid and FB.isLoggedIn stays false

here’s the LogCat of the reply i get

sending to Unity OnLoginComplete({“key_hash”:“n0RW5G6…8HF8AjM8=\n”,“access_token”:“CAAG3N…jxzwZDZD”,“opened”:true})

even though the reply seems to contain the access_token, the FB.accessToken stays empty

I understood why when the device is installed a facebook app, my app can’t login facebook.

  • First : software OpenSSL create keyhass wrong. I have downloaded OpenSSL from here : Google Code Archive - Long-term storage for Google Code Project Hosting. , and it creates keyhash wrong.
    I have used other OpenSSL sofware, you can download it here : Dropbox - Error - Simplify your life , it is create keshash right.

  • Second: In class FacebookAndroidUtil.cs , line 62, you add System.Environment.GetEnvironmentVariable(“HOMEDRIVE”) before System.Environment.GetEnvironmentVariable(“HOMEPATH”). Facebook SDK requires a file debug.keystore in : C:\Users\UserName.android\debug.keystore.
    If the Unity Editor, Edit Setting Facebook has yet to create android debug hash key. Then use the Eclipse Software, create and run onr any project. Eclipse will generate a debug.keystore. If it is’t create in folfer : C:\Users\UserName.android\debug.keystore , then find it, coppy and paste into C:\Users\UserName.android\debug.keystore

  • Third: publish your app in Facebook, so be sure it is:“This app is public and available to all users”.

@splendor can you post a copy of your FacebookAndroidUtil.cs file please? I’m still having problems.

Fixed it! I ran adb logcat *:W and got the correct hash from the logs.

@splendor the OpenSSL file you linked to got flagged up as a trojan on my anti virus…

Glad to know! :slight_smile:
Can you please describe in detail the process you follow to make this work?
thanks.

Sampora, you are 10000% correct,

#WORKS GREAT IF YOU do NOT have THE FB APP INSTALLED ON THE ANDROID DEVICE

WILL NOT WORK IF THE USER HAPPENS TO HAVE THE FB APP INSTALLED.

what a drama!

a lot of the solution is here …

note that Brian J., from Facebook, is discussing it there.

Note – in many cases the solution is very simple:

YOU FORGOT TO “ADD A PLATFORM” ON developers.facebook,

you have to add the Android platform, AND

you must paste in the package name / class name / key hash values

(As Brian J. explains there)

Hope it helps someone!

No I didn’t. I still cannot log in. On Windows it works nice. It asks for token and then I can see friends and co… but on my android device cannot login. I just get “Cancelled by Player” something like that.

I have a platfomr there. I put package name, class name, key hash too. Everything took from unity editor. But doesn’t work :frowning:

Here is the solution !!

the “Rafael solution”.

Thanks. It is confirmed? Someone said that the dropbox link has a trojan virus.
I already tested with different openssl version. same hash values.

But I will try the second solution.

EDIT: oh you said “Rafael solution” will check it.

Hi Mazy – obviously I’m talking about the ACCEPTED ANSWER, the one in green

It’s extremely fortunate Rafael figured that out ! it’s the only solution if you’re on Mac, BTW.

My solution was:

1 . Get the fingerprint SHA1 (keytool -printcert -file CERT.RSA)
2 . Copy the SHA1 HEX and convert that code to Base 64 (Hex to base64 converter)
3 . You should copy the fingerprint in base 64 in the Android key hashes on your facebook app configuration.

That was all and it worked perfectly!