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


当前回答

This required no coding input. Go to Android Studio-> 
Click on Right side panel "Gradle"=>
*Your App Name =>
*Your App Name(root)=>
*Tasks=>
*android =>
*Double click on **signinReport**=>
Will get 
example :
SHA1: [![6A:DE:ED:5A:9F:0B:19:47:38:DC:DE:3B:7B:A2:D7:4C:6C:0A:24:70][1]][1]

Go to 

http://fbkeyhash.com/index.php
Paste your SHA-1

其他回答

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

    }
}

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

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

将此代码添加到您的活动的onCreate,它将在您的logCat的KeyHash标签下打印散列

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           getPackageName(),
                           PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
}
catch (NameNotFoundException e) {

}
catch (NoSuchAlgorithmException e) {

}

您可以为您的帐户添加多个hashkey,所以如果您一直在调试中运行,不要忘记在发布模式中再次运行此命令。

下载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

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