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


当前回答

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

其他回答

您可以从SHA-1密钥获得密钥哈希。 这很简单,你需要得到你的SHA-1(签名APK)密钥从Play Store检查下图。

现在复制SHA-1密钥并在这个网站http://tomeko.net中过去,也检查下面的图像以获得您的密钥哈希。

我犯了一个小错误,应该记住。如果你正在使用你的密钥库,那么给出你的别名,而不是androiddebugkey…

我的问题解决了。现在,如果我的设备上安装了Facebook,那么我的应用程序仍然在Facebook登录集成上获得数据。只关心你的哈希键。

请看下文。

C:\Program Files\Java\jdk1.6.0_45\bin>keytool -exportcert -alias here your alias name  -keystore "G:\yourkeystorename.keystore" |"G:\ssl\bin\openssl" sha1 -binary | "G:\ssl\bin\openssl" base64

然后按Enter -它会要求您输入密码,然后输入您的密钥库密码,而不是Android。

酷。

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

下载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位的键码

[EDIT 2020]->现在我完全推荐这里的答案,使用android studio更容易,更快,不需要写任何代码-下面这个是在eclipse时代的:)-。

您可以在任何活动中使用此代码。它将在logcat中记录hashkey,这是调试键。这很简单,而且比使用SSL轻松。

PackageInfo info;
try {
    info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String something = new String(Base64.encode(md.digest(), 0));
        //String something = new String(Base64.encodeBytes(md.digest()));
        Log.e("hash key", something);
    }
} catch (NameNotFoundException e1) {
    Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
    Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
    Log.e("exception", e.toString());
}

你可以在知道密钥后删除代码;)