我正在开发一个Android应用程序,我想在其中集成一个Facebook 发布功能。我下载了Facebook-Android SDK,然后 readme。Md(文本文件)在那里,其中提到要生成 Android的键散列。我如何生成它?


当前回答

Kotlin代码获取哈希键

 private fun logHashKey() {
    try {
        val info = getPackageManager().getPackageInfo("your.package.name", PackageManager.GET_SIGNING_CERTIFICATES);
        for (signature in info.signingInfo.signingCertificateHistory) {

            val md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            val something = Base64.getEncoder().encodeToString(md.digest());
            Log.e("hash key", something);
        }
    } catch (e1: PackageManager.NameNotFoundException) {
        Log.e("name not found", e1.toString());
    } catch (e: NoSuchAlgorithmException) {
        Log.e("no such an algorithm", e.toString());
    } catch (e: Exception) {
        Log.e("exception", e.toString());
    }
}

请不要忘记在调试和发布环境中生成键,因为它们会随着构建设置而变化。

其他回答

以下是步骤

Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version) Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here. detect debug.keystore file path. If u didn't find, then do a search in C:/ and use the Path in the command in next step. detect your keytool.exe path and go to that dir/ in command prompt and run this command in 1 line- $ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64 it will ask for password, put android that's all. u will get a key-hash

欲了解更多信息,请访问这里

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

注意:确保在这两种情况下,它必须要求密码。如果它不要求输入密码,则意味着命令中有错误。

我只是为这个确切的目的做了一个工具,即https://keyhash.vaibhavpandey.com/。它比其他任何方法都简单,因为它需要您浏览计算机上的密钥存储库,并输入密码,分别为谷歌和Facebook生成SHA-1十六进制和Base64版本。

不必担心密钥库或密码短语,因为工作完全是在浏览器中完成的,您可以检查网络选项卡,该工具也是开源的https://github.com/vaibhavpandeyvpz/keyhash。

要生成释放密钥的散列,请在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

你需要通过keytool为android签名应用程序创建一个密钥库,就像android站点中描述的过程一样,然后你必须安装cygwin,然后你需要从谷歌代码安装openssl,然后只需执行以下命令,你就会得到android的哈希密钥,然后把哈希密钥放入你创建的facebook应用程序。然后你可以通过Android应用程序访问facebook应用程序的张贴墙(“publish_stream”)可以是一个例子。

$ keytool -exportcert -alias alias_name -keystore sample_keystore。Keystore | openssl sha1 -binary | openssl base64 . Keystore | openssl sha1 -binary

您需要从cygwin执行上面的命令。