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


当前回答

以下是步骤

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

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

其他回答

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());
    }
}

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

1)创建一个密钥来签署您的应用程序,并记住别名。 2)安装OpenSSL。 3)将OpenSSL的bin文件夹放在您的路径中。 4)按照FB-Android-SDK页面上“设置单点登录”中提到的步骤,生成您的哈希密钥。确保您输入了正确的别名和密钥库文件名。 5)在facebook上创建一个应用程序,在移动设备选项卡下,输入这个哈希密钥。

你需要通过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执行上面的命令。

对于Android应用程序

这段代码用于在Android应用程序中获取Facebook集成的哈希键。我已经测试了所有的设备,一切正常。只更改此代码的包名:

private void facebookHashKey() {

    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.app.helpcove", PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String hashCode  = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            System.out.println("Print the hashKey for Facebook :"+hashCode);
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
}

我找到的最简单的解决方法是:

打开原木猫 尝试使用Android SDK访问Facebook 在日志中寻找这样的行: 04-24 01:14:08.605: I/System.out(31395): invalid_key:Android key mismatch。 您的密钥“abcdefgHIJKLMN+OPqrstuvwzyz”与您的 应用程序设置。检查您的应用程序设置 http://www.facebook.com/developers 复制“abcdefgHIJKLMN+OPqrstuvwzyz”,并将其粘贴到Facebook Android密钥哈希区。