Blackecho
Blackecho

Reputation: 1290

Invalid Key hash with Facebook Android SDK

I'm trying to use Facebook Android SDK to develop a simple app with the Facebook Login Button. But i'm having trouble with Key Hashes. I've created both a debug key and a release key:

Debug key:

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

Release key:

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

And then i copied this key hashes in the Facebook Developers page. When i export the apk and copy it into the device it works well, but when i try to install the app from Eclipse (run as/debug as Android Application) it doesn't work. It seems that the app is using a different key hash from the one i've created with keytool. Anyone knows how to solve this problem?

Upvotes: 3

Views: 16571

Answers (3)

msevgi
msevgi

Reputation: 4904

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

      }
      catch (NoSuchAlgorithmException e) {

      }

Upvotes: 0

Bhaskar.Ramagiri
Bhaskar.Ramagiri

Reputation: 21

 try {
            PackageInfo info = getPackageManager().getPackageInfo("your pakage name here", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.e("KeyHash:", "key is: "+Base64.encodeToString(md.digest(), Base64.DEFAULT));

                }
        } catch (NameNotFoundException e) {

            Log.e("error","error name not found");
        } catch (NoSuchAlgorithmException e) {

            Log.e("error","error no algorithm");

        }**strong text**

By using this one u can get ur key hash and then use this one in facebook devloper site.

Upvotes: 2

Mayank Saini
Mayank Saini

Reputation: 3017

Try to get the HashKey from here

public static void showHashKey(Context context) {
            try {
                PackageInfo info = context.getPackageManager().getPackageInfo(
                        "com.example.tryitonjewelry", PackageManager.GET_SIGNATURES); //Your            package name here
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                    }
            } catch (NameNotFoundException e) {
            } catch (NoSuchAlgorithmException e) {
            }
        }

Upvotes: 23

Related Questions