我正在开发一个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页面。

其他回答

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

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

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

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

keytool -exportcert -alias androiddebugkey -keystore       C:\Users\pravin\.android\debug.keystore | "H:\OpenSSL\bin\openssl" sha1 -binary | "H:\OpenSSL\bin\openssl" base64

这对我很管用……

步骤:

1) Open command line go to - > java Keytool..... for me C:\Program Files\Java\JDK1.7\bin
2) Download OpenSSL from google
3) paste this with changing your paths -
   keytool -exportcert -alias androiddebugkey -keystore C:\Users\pravin\.android\debug.keystore | "H:\OpenSSL\bin\openssl" sha1 -binary | "H:\OpenSSL\bin\openssl" base64 

    ....................   give proper debug.keystore path and openSSL path .. 

4) Finley it may be ask u password .. so give password -> android   ...
5) you will get 28 characters that will be your has key

这是Xamarin的版本


private void printKeyHash()
{
    try
    {
        PackageInfo info = PackageManager.GetPackageInfo(PackageName, PackageInfoFlags.Signatures);
        foreach (var signature in info.Signatures)
        {
            MessageDigest md = MessageDigest.GetInstance("SHA1");
            md.Update(signature.ToByteArray());
            var hash = Base64.EncodeToString(md.Digest(), Base64Flags.Default);
            Log.Debug("KeyHash:", hash);
        }
    }
    catch (PackageManager.NameNotFoundException e)
    {

    }
    catch (NoSuchAlgorithmException e)
    {

    }
}