2013年9月2日 星期一

facebook android get key hash

20140429: http://stackoverflow.com/questions/6661993/how-to-generate-key-hash-for-facebook-sdk-in-mac

get key hash
  1. First open a terminal (open a command prompt in windows).
  2. Navigate in the terminal to the directory where your Android debug.keystore is stored.
  3. Mostly it will located under “/Users/user_name/.android/” (In Windows will be C:\Documents and Settings\.android).
  4. Once you are in the “.android” directory, run the following command.
    keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

    keytool -exportcert -alias yourappreleasekeyalias -keystore ~/.your/path/release.keystore | openssl sha1 -binary | openssl base64
  5. When it prompts you for a password, type android and hit Enter
  6. Copy the value printed in the terminal that ends with an “=” and paste it in the Key Hash field in Facebook. Then click the Save Changes button.

get start

1. import facebook sample 一直run失敗

2. 重新 create 一個專案,用複製貼上 就正常了

3.get keyhash
try {
    PackageInfo info = getPackageManager().getPackageInfo(
            "ENTER.YOUR.PACKAGE.NAME", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.e("MY KEY HASH:",
                Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
} catch (NameNotFoundException e) {

} catch (NoSuchAlgorithmException e) {
原po
http://stackoverflow.com/questions/14875027/android-facebook-remote-app-id-does-not-match-stored-id-error

ps: build apk 之後 就 hash key 又不同了。