7

Possible Duplicate:
Login failed invalid key error with Facebook SDK

I am using a sample app for here ibm.com/developerworks/library/x-androidfacebookapi/ to test facebook android SDK, I have given my APP ID in this sample app. I have done all setups and prerequisites. I have signed app with my keystore and generated hash key I submitted hash key to facebook app settings page, I installed facebook app on my device. But after all doing the app gives Facebook error invalid_key. Pls help me in this regards, Thank you.

Community
  • 1
  • 1
om252345
  • 2,395
  • 4
  • 29
  • 31

12 Answers12

10

Invalid Key could be for a number of reasons -

  1. Make sure you have Keytool and OpenSSL installed.
  2. Make sure you are giving the correct Keystore file in the command.
  3. Make sure you are giving the correct Alias.
  4. Make sure you copied the generated Hash Key correctly to the Facebook application correctly.

When I got Invalid Key initially, it was because I was giving the wrong Alias. The strange thing is, that Keytool and OpenSSl won't mention that the alias is wrong. If you give the command to generate the Hash Key, and it doen't ask you for your password, you're probably doing it wrong.

Abhinav Manchanda
  • 6,546
  • 3
  • 39
  • 46
  • Hi,I created a new key and generated a key hash for same, i submitted that hash to facebook and signed app with that key, but it is not working. Same invalid_key error is coming. On facebook app settings page where we input hash key what should be the value of RADIO button HTML5/WEB or NATIVE? – om252345 Dec 21 '10 at 12:00
  • It should be HTML5/Mobile Web. Native app means it came built in with the phone. Can you try out using the Eclipse debug keystore, and see if it works with that ? – Abhinav Manchanda Dec 21 '10 at 15:11
  • Hi abhinav, yes I tried with debug key and generated hash, it also gives facebook error, one strange behaviour is that when I updated facebook app on device the old installed apps are working with sso but new installed different apps with same key sign are giving facebook error..... – om252345 Dec 22 '10 at 05:06
  • When I put in the wrong key, Android showed the same behaviour in my case. I still somehow have the feeling that you're putting in the wrong key hash. I hope you're using the following command : keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64 – Abhinav Manchanda Dec 22 '10 at 06:13
  • 2
    Moreover, make sure you're in the correct folder, and the password given is "android" – Abhinav Manchanda Dec 22 '10 at 06:15
  • How would I know what the correct alias is? – IgorGanapolsky Aug 31 '12 at 15:55
  • for the debug key it's always androiddebugkey. If you don't key this in, it will probably not ask you for a password. – Abhinav Manchanda Sep 03 '12 at 09:15
9

After a few days of struggling with the same issues, I wrote up a full explanation of the problem and the various fixes here:

http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/

Sean Lynch
  • 705
  • 8
  • 10
3

A few things I ran into before I got this working:

1) Generate your hash in linux. Windows (at least for me, 64-bit) didn't generate the correct hash. Download the Cygwin bash shell and do it from there.

2) In the filepath for the keystore, everything should be a forward slash. Even in front of C:. So, for example, C:/Users/YourName/.android/debug.keystore, NOT C:\Users/YourName/.android/debug.keystore.

3) The equals at the end of the hash should be included. Maybe this was obvious to some people, but nevertheless I thought I should mention it.

It SHOULD prompt you for a password. If it doesn't, you've done something incorrectly.

Seth Nelson
  • 2,598
  • 4
  • 22
  • 29
2

I also had this problem, didn't really find how to resolve it untill I found this

http://support.getsocialize.com/socialize/topics/facebook_auth_key_issue_adding_the_invalid_key_from_logcat_seems_to_fix_sso?from_gsfn=truethread.

Every help topic states that the key hash hasn't been filled in correctly. After checking multiple times and using the keytool multiple times I knew I filled it in correctly. The above link goes to a toppic on Get Satisfaction about this issue, and the sollution that is offered there worked for me. Just copy the key you see in the popup into the hash box on your facebook developer page. It can be added alongside the hash you get from keytool.

Some things I found out while resolving this problem. - I always used the full path in the keytool command - when entering the keytool command make sure it asks for a password - to find out if you correctly typed your password in de keytool command first supply it with something, that you know is not, your password cause it will also generate a hash. If the password is incorrect it will always give the same hash. so to check if you typed in your password correct compare it to a hash of a wrong password. - This error only occurs if the facebook app is also on the phone, which I believe means that the error is not in the authentication itself, this made me search for errors in my code for hours while there were none (at least not in the authentication part :p) - I was fortunate enough to have multiple test devices, which showed me it was not an error in the code but an error in the sdk or in some other part in the authentication phase.

I hope this info will help someone that runs into this problem and save him some time in resolving it.

kind regards Tom

Tom Groentjes
  • 1,053
  • 8
  • 7
  • This was exactly my problem! I was impulsively entering my sudo password for my debug keystore and it didn't complain and gave me a hash output. As soon as I entered no password for my debug keystore the keytool output the same signature that FB expected! WEIRD WEIRD! – swooby Feb 17 '15 at 19:33
1

Been having problems with this all day, I used cmd prompt to generate the key and it worked after I defined the path of openssl and keytool in the windows system settings.

I set up the Facebook application in eclipse and it was working fine on the AVD, however the same program causes the Facebook error invalid key when installed on my nexus s.

I've come to the conclusion that the device has its own keys and cannot use those in the keystore.

Dave P
  • 11
  • 1
0

It is not logical bu "The Same" keytool command gives different results in Windows and Linux. The hash key got from Linux works, from Windows fails. You can try that!

The openssl in Windows installed from here: http://code.google.com/p/openssl-for-windows/

enesness
  • 3,123
  • 5
  • 31
  • 33
0

I have had the same problem and finally I found the solution : Use Cygwin for Windows users. The result from Windows is different from linux/iOS. So install Cygwin, it's very easy and you will also need cygwin if you want to work with NDK. Run the command listed above copy the output and it will work.

Sebastian
  • 236
  • 1
  • 3
  • 6
0

Actually this is the problem in facebook sdk if you uninstall the com.facebook.katana then your application will work perfectly fine. I don't have a permanent solution for this problem but temporarily it will work

Hasandroid
  • 336
  • 5
  • 12
0

Today, you can't get a correct key with Windows EVEN using Cygwin. You must do it under MacOS or Linux. This is an issue. Hope they get it fixed very soon.

MrBuBBLs
  • 459
  • 6
  • 15
0

I was having this same problem and I think many others are running into the same thing that I was. The key store on windows is under the user directory by default e.g. C:\Users\User Name.android\

It failed for me because I was entering the full path and it had a space (" ") in folder that is named after the user. If you put quotes around the path it will likely work, and you should be prompted for the keystore password.

e.g. keytool -exportcert -alias androiddebugkey -keystore "C:\Users\User Name.android" | openssl sha1 -binary | openssl base64

Michael DeBerry
  • 183
  • 1
  • 9
0

I'm using windows 7 and fix problem using :

keytool -export -alias androiddebugkey -keystore "[PATH]\debug.keystore" -storepass android -keypass android | openssl sha1 -binary | openssl enc -a -e

You can download OpenSSL for Windows

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
0

i fix the bug with this:

if you add to authorize line this code

Facebook.FORCE_DIALOG_AUTH

mFacebook.authorize(MundialRugby2011Activity.this, 
new String[] {"publish_stream", "read_stream",                             
    "offline_access"},Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
Bostone
  • 36,858
  • 39
  • 167
  • 227