eclipse Facebook Android SDK 的密钥哈希无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24953263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Invalid Key hash with Facebook Android SDK
提问by Blackecho
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:
我正在尝试使用 Facebook Android SDK 开发一个带有 Facebook 登录按钮的简单应用程序。但是我在使用密钥哈希时遇到了麻烦。我已经创建了调试密钥和释放密钥:
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?
然后我在 Facebook 开发人员页面中复制了这个密钥哈希。当我导出 apk 并将其复制到设备中时,它运行良好,但是当我尝试从 Eclipse 安装应用程序(作为 Android 应用程序运行/调试)时,它不起作用。该应用程序使用的密钥哈希似乎与我使用 keytool 创建的密钥哈希不同。有谁知道如何解决这个问题?
回答by Mayank Saini
Try to get the HashKey from here
尝试从这里获取 HashKey
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) {
}
}
回答by Bhaskar.Ramagiri
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.
通过使用这个,你可以获得你的密钥哈希,然后在 facebook devloper 站点中使用这个。
回答by android_developer
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) {
}