假设您使用的是最新的 3.0 SDK,请尝试以下两个选项:
选项 1:(Windows)
%KEYTOOLPATH%\keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | %OPENSSLPATH%\openssl sha1 -binary | %OPENSSLPATH%\openssl base64
例子:
C:\Program Files (x86)\Java\jdk1.7.0_09\bin\keytool" -exportcert -alias androiddebugkey -keystore "C:\Home\.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary | "C:\OpenSSL\bin\openssl" base64
使用密码:android
选项 2:(打印发送到 FB 的密钥哈希)
(适用于 Android 的 Facebook SDK 的变体 - 示例应用程序不起作用)
将此代码添加到您的活动中:
try {
PackageInfo info = getPackageManager().getPackageInfo("your package name, e.g. com.yourcompany.yourapp]", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
示例:在 HelloFacebookSampleActivity 中,对 onCreate() 方法进行如下临时修改
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.hellofacebook", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
...
}
运行您的示例,您应该在 KeyHash 标记上获得 logcat 输出,类似于:
12-20 10:47:37.747: D/KeyHash:(936): 478uEnKQV+fMQT8Dy4AKvHkYibo=
在 Facebook 的 App Dashboard 设置中为您的应用使用该值。