我正在开发一个Android应用程序,我想在其中集成一个Facebook 发布功能。我下载了Facebook-Android SDK,然后 readme。Md(文本文件)在那里,其中提到要生成 Android的键散列。我如何生成它?
当前回答
1)创建一个密钥来签署您的应用程序,并记住别名。 2)安装OpenSSL。 3)将OpenSSL的bin文件夹放在您的路径中。 4)按照FB-Android-SDK页面上“设置单点登录”中提到的步骤,生成您的哈希密钥。确保您输入了正确的别名和密钥库文件名。 5)在facebook上创建一个应用程序,在移动设备选项卡下,输入这个哈希密钥。
其他回答
将此代码添加到您的活动的onCreate,它将在您的logCat的KeyHash标签下打印散列
try {
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(),
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) {
}
您可以为您的帐户添加多个hashkey,所以如果您一直在调试中运行,不要忘记在发布模式中再次运行此命令。
这是Facebook官方页面上给出的内容:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
让我把这个命令分解成几个片段。
Look for "keytool.exe". You can search that on the C: drive. You can find it in "java jdk" or "java jre". If you have installed multiple versions, choose any. Open a CMD prompt and go to the above directory where you found "keytool.exe". Clip the "exe`" and paste the above command provided on the Facebook page. You will get an error on entering this that OpenSSL is not recognized as in input output command. Solution : Download "Openssl" from OpenSSL (if you have a 64-bit machine you must download openssl-0.9.8e X64). Extract and save it anywhere... I saved it on the C: drive in the OpenSSl folder Replace the openssl in the above command in which you was getting an error of OpenSSL with "C:\OpenSSL\bin\openssl" at both the places after the pipe, "|". If prompted for a password, enter android.
你会得到你的哈希键。要了解进一步的步骤,请再次参考Facebook页面。
要生成释放密钥的散列,请在Mac或Windows上运行以下命令,替换释放密钥别名和密钥存储库的路径。
在Windows上,使用:
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
这个命令应该生成一个28个字符的字符串。记住,复制并粘贴这个释放键哈希到你的Facebook应用ID的Android设置。
图片:fbcdn-dragon-a.akamaihd.net/hphotos-ak-xpa1/t39.2178-6/851568_627654437290708_1803108402_n.png
参考网址:https://developers.facebook.com/docs/android/getting-started#release-key-hash和http://note.taable.com
Linux
开放式终端:
用于调试构建
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
你会发现debug。Keystore来自”。Android "文件夹复制并粘贴在桌面上,并运行上述命令
发布版本
keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64
注意:确保在这两种情况下,它必须要求密码。如果它不要求输入密码,则意味着命令中有错误。
我已经这样做了Linux操作系统和Windows操作系统:
Linux:
下载Openssl 打开终端 keytool -exportcert -alias **myaliasname** -keystore **/home/comp-1/Desktop/mykeystore. xmlJks ** | openssl sha1 -binary | openssl base64
请更改别名和Keystore与它的路径作为您的要求。
终端将询问密钥库的密码。您必须为相同的密钥存储库提供密码。
最后你会得到Release Hashkey。
窗口:
释放Hashkey的步骤:
下载Openssl(从这里下载),我已经下载了64位操作系统,你可以在这里找到更多 解压下载的zip文件到C:只\驱动器 打开命令提示符 "C:\Users\hiren.patel\Desktop\mykeystore. keytool -exportcert -alias **myaliasname** -keystore **"\openssl-0.9.8e_X64\bin\openssl.exe" sha1 -二进制| "C:\openssl-0.9.8e_X64\bin\openssl.exe" base64
请更改别名和Keystore与它的路径作为您的要求。
注意:请将您的详细信息放在我标记的** **之间。
终端将询问密钥库的密码。您必须为相同的密钥存储库提供密码。
最后你会得到Release Hashkey。
Done
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- 如何测试Facebook本地连接
- 我如何找到哪个程序正在使用端口80在Windows?
- 在Windows中有像GREP这样的模式匹配实用程序吗?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- 如何在iOS中使用Swift编程segue
- 如何在Windows命令提示符下运行.sh ?