2
votes

i try to integrate facebook sdk (version :3.14 ) to my app but i quickly get into trouble with keyhash

when i run command

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

i got this key hash: XHAAVbh9dOufRUPyIWm/9ws5q10=

but when i try to run facebook sample to post something to fb wall ( project name: HelloFaceBookSample) I get damm error, it confuse me very much because in logcat i take error log:

com.facebook.http.protocol.ApiException: (#404) Key hash XHAAVbh9dOufRUPyIWm_9ws5q10 does not match any stored key hashes.

did facebook sdk get wrong key hash ??

2

2 Answers

3
votes

Use this in your code, to get the keyhash:

public void KEY(){
        try {
            PackageInfo info =     getActivity().getPackageManager().getPackageInfo("com.YourPackageName",     PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
                Log.e("MY KEY HASH:", sign);
                Toast.makeText(getActivity().getApplicationContext(),sign,     Toast.LENGTH_LONG).show();
                System.out.println(sign); 
            }
        } catch (NameNotFoundException e) {
        } catch (NoSuchAlgorithmException e) {
        }
    }

Make sure you supply the correct key Hash on the FB dev console.

3
votes

If you are using eclipse you can directly use this link to generate your hash key.

Just go to Eclipse -> window -> preferences -> Android -> Build . And copy the SHA1 value and paste it in the link provided below. You can use the key hash generated from the site and paste it on Facebook settings.

http://tomeko.net/online_tools/hex_to_base64.php?lang=en