4

I'm getting login failed invalid key error while using an updated version of Facebook. If I delete it - it's working fine..

What is the correct way of creating a hash key?

I know that there are a lot of questions and answers for single sign on in Android, but none helped me to implement single sign-on in Android.

My code:

public class Main extends Activity {
    Facebook facebook = new Facebook("XXXXXXXXXX");

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        facebook.authorizeCallback(requestCode, resultCode, data);
    }
}

Then I generated a hash key using the command

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

Also, I am having OpenSSL and given the location of OpenSSL upto openssl.exe..

After I hit Enter it is asking for a password and I gave android as the password. Then I got a key and filled in "My Application".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Venky
  • 11,049
  • 5
  • 49
  • 66

5 Answers5

7

The correct way to create a hash key

Please follow the following steps.

Here are the steps:

  1. Download OpenSSL from Google Code

  2. Extract it. Create a folder- OpenSSL in C:/ and copy the extracted code here.

  3. detect the debug.keystore file path. If you don't find it, then do a search in C:/ and use the path in the command in next step.

  4. detect your keytool.exe path and go to that dir/ in a command prompt and run this command (in one line):

    $ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64

  5. it will ask for a password. Put "android", that's all. You will get a key-hash.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AndroidDanger
  • 1,049
  • 1
  • 9
  • 17
6

First, you need to create the hash key using the below code according to your path.

C:\Documents and Settings\Logistic103>keytool -export -alias androiddebugkey -keystore "C:\Documents and Settings\Logistic103\.android\debug.keystore" | E:\Downloads\openssl-0.9.8k_WIN32\bin\openssl.exe sha1 -binary | E:\Downloads\openssl-0.9.8k_WIN32\bin\openssl.exe enc -a -e

Then enter the password:

Enter keystore password:  android

Then go to Facebook developers and login into Facebook. After login goto your application and click on edit setttings link:

Enter image description here

Then add the generated key as under to your application,

Enter image description here

And that's how you do it ;)

The above steps works well for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Maulik J
  • 2,745
  • 19
  • 22
  • @Venky hi, I was having the same problem before 4-5 months and I finally solved it by following the above steps, but I remember that I had changes some code in facebook api but I dont remember it rit now, i ll revert u asap – Maulik J Oct 19 '11 at 12:01
0

better use this piece of code

  try {
        PackageInfo info = getPackageManager().getPackageInfo("your.package",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("YOURHASH KEY:",
                    Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
bmkay
  • 462
  • 6
  • 9
0

Please follow this link Generate correct Hash Key

You can generate Hash key problematically for both signed and unsigned app. And copy this key from your Logcat.

Community
  • 1
  • 1
Atul Bhardwaj
  • 6,647
  • 5
  • 45
  • 63
-1

Well, this might not be an answer, I guess you checked Android, the Facebook SDK, SSO, and You.

Are you using Windows XP for generating a hash? Maybe there lies the problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pratik Bhat
  • 7,166
  • 2
  • 35
  • 57
  • wel, it may not be an error of invalid key at all, i had a similar error, of invalid access token...saying user might have changed his password... but actually it was a different issue – Pratik Bhat Oct 18 '11 at 12:31