问题描述
我正在构建一个用户可以使用 Facebook 登录的应用.
我已经创建了如下的哈希键:
尝试{包信息信息 = getPackageManager().getPackageInfo("com.app.package",PackageManager.GET_SIGNATURES);for(签名签名:info.signatures){MessageDigest md = MessageDigest.getInstance("SHA");md.update(signature.toByteArray());Log.d("KeyHash", "KeyHash:"+ Base64.encodeToString(md.digest(),Base64.DEFAULT));Toast.makeText(getApplicationContext(), Base64.encodeToString(md.digest(),Base64.DEFAULT), Toast.LENGTH_LONG).show();}} catch (NameNotFoundException e) {} catch (NoSuchAlgorithmException e) {}
在调试模式下,一切正常.
当我导出项目进行发布时,出现此错误:
无效的密钥散列.密钥散列 ****************** 不匹配任何存储的密钥散列"
我粘贴了 Facebook 开发者仪表板中打印的密钥,但应用程序仍然出现该错误.
我的活动的完整包是com.app.package.views
",我尝试在仪表板中使用这个包(作为 Google Play 包名称),但没有任何改变.>
我该如何解决?如何生成正确的发布密钥哈希?
您是否按照 facebook 提供的步骤创建登录应用程序?
您需要在启动发布密钥库时获得生产密钥哈希":
来自命令行:
keytool -exportcert -alias -keystore |openssl sha1 -binary |openssl base64
并在 facebook 应用页面选项中添加此密钥.
更多信息:https://developers.facebook.com/docs/android/入门/
I'm building an app in which users can log in with Facebook.
I've created the hash keys like following:
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.app.package",
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));
Toast.makeText(getApplicationContext(), Base64.encodeToString(md.digest(),
Base64.DEFAULT), Toast.LENGTH_LONG).show();
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
In debug mode, everything works well.
When I export the project for release, it gives this error:
"Invalid key hash. The key hash ****************** does not match any stored key hashes"
I paste the key printed in the Facebook Developer dashboard, but the application still gives me that error.
The complete package of my actvity is "com.app.package.views
" and I tried to use this package (as Google Play Package Name) in the dashboard, but nothing changed.
How can I solve it? How can I generate the right release key hash?
You followed the steps that facebook provides for the creation of a login application?
You need a 'Production keyhash' obtained starting your release keystore:
From comand line:
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
And add this key on facebook app page options.
More information: https://developers.facebook.com/docs/android/getting-started/
这篇关于Android Facebook SDK:生成发布密钥哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!