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


当前回答

对于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) {

    }
}

其他回答

下载openSSL for windows,你可以在这里找到64位和32位的 解压缩下载的文件 在C盘中创建文件夹名为openSSL 将所有提取的项目复制到openSSL文件夹(bin,include,lib, openSSL .cnf) 获取android调试密钥库,默认位置为

C:\Users\username\.android\ debug.keystore

现在获得命令提示符并粘贴这段代码

keytool -exportcert -alias androiddebugkey -keystore C:\Users\username.android\debug.keystore |“C:\openSSL\bin\openssl” sha1 -binary |“C:\openSSL\bin\openssl” base64

按enter键,你会得到28位的键码

以下是步骤

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

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

这是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页面。

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

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

在Android Studio中,只需点击右侧侧边栏面板“Gradle”即可显示gardel面板: -YOURAPPNAME ——任务 ——安卓 ----(双击)signingReport(启动Gradle Daemon)

然后你会看到结果:

Config: debug
Store: C:\Users\username\.android\debug.keystore
Alias: AndroidDebugKey
MD5: C8:46:01:EA:36:02:D1:21:1B:23:19:91:D4:32:CB:AC
SHA1: 38:AB:4C:01:01:D7:62:E0:61:D1:9F:52:04:0C:E5:07:4E:E4:9B:39
SHA-256: 1B:8C:DC:35:48:10:01:2C:1F:BD:01:64:F1:01:06:01:60:01:A6:8B:10:15:2E:BF:7B:C4:FD:38:4C:C1:74:01
Valid until: Saturday, February 12, 2050

SHA1副本:

38:AB:4C:01:01:D7:62:E0:68:D1:9F:52:04:0C:E5:07:4E:E4:9B:39

进入本页

粘贴SHA1并生成您的Facebook密钥哈希代码。