且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我得到不同的键盘注册Facebook应用程序?

更新时间:2022-12-22 12:40:37

你至少需要2个键哈希你的申请。这是假设,你只在一台电脑上工作。对于其他计算机,您需要在开发者控制台中生成并再次添加一个Key Hash到您的App的设置。



说明:在测试应用程序时,eclipse(与ADT / SDK一起使用)将始终使用 debug.keystore 将应用推送到设备或模拟器。当您发布应用程序时,您可以使用为您的应用程序生成的密钥库(用于发布到Google Play)。



Facebook需要使用键盘哈希来进行debug.keystore以及您自己的密钥库。



为了解决您担心使用两种不同方法获得不同的密钥哈希,当我开始使用Facebook Android SDK时遇到了一些问题。为了规避这个问题,我发现一个总是有效的,总是精确的解决方案。您可以按照这些答案中的步骤(它们几乎相同),您将无需任何时间使用您的密钥哈希:


  1. https://***.com/a/13283088/450534

  2. https://***.com/a/13343529/450534

  3. https://***.com/a/10516629/450534 (该解决方案在本文的评论中)

所以,总结一下:


  1. 尝试使用步骤上面提供的链接让Facebook SDK告诉您正确的密钥哈希。

  2. 以及使用哪个密钥哈希:您不必决定。由于您将两个密钥哈希添加到开发者控制台,Facebook将自动使用适当的哈希。

  3. 我不知道需要将密钥哈希添加到清单文件。这可能是Facebook SDK v3的一个要求。在这种情况下,在测试时,使用通过 debug.keystore 创建的密钥哈希,当您准备发布应用程序时,更改为使用您的版本密钥库创建的密钥哈希

希望这能解决您的问题。 b
$ b

编辑



如已指出的Offbeatmammal,您可以向开发者控制台添加多个密钥哈希。所以存储和使用多个密钥哈希是你不必担心的。


I have tried

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

And I get a keyhash 1knQ67Fx4PUOYXggSe+mnzqaTL8=.

But google's own documentation suggests an alternative too.

try {
    PackageInfo info = getPackageManager().getPackageInfo(
            "com.facebook.samples.hellofacebook", 
            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) {
}

But this yields UR02fNgzyMOjpWCxUnjGZ4ctF6Y=. I have doubly verified that and I get these two values consistently with the respective approaches.

Why are they different? And which one should I register at developers.facebook.com? The documentation is not very clear it seems.

Edit:

As Offbeatmammal says I can register multiple keys at facebook site. So that's ok. But I should also specify the keyhash in application manifest file. So additionally asking: which one should I use there in the application? I can of course try it but an answer would be welcome as well.

You will essentially need at least 2 Key Hashes for your application. This is assuming, you are working on just one computer. For additional computer, you will need to generate and add one more Key Hash to your App's settings in the Developer Console.

Explanation:

While you are testing your application, eclipse (in conjunction with the ADT / SDK) will always use the debug.keystore for pushing the app to the device or the emulator. When you publish the app, you use the keystore that you generate for your app (for publishing to Google Play).

Facebook requires the Key Hashes for both the debug.keystore as well as your own keystore.

To address your concern that you get different Key Hashes using 2 different methods, is something I have faced when I started using the Facebook Android SDK. To circumvent that, I found a solution that always works and is always precise. You can follow the steps in these answers (they are almost the same) and you will have your Key Hash working in no time:

  1. https://***.com/a/13283088/450534
  2. https://***.com/a/13343529/450534
  3. https://***.com/a/10516629/450534 (The solution is in the comments in this one)

So, to sum it up:

  1. Try using the steps from the links provided above to let the Facebook SDK tell you the correct Key Hash.
  2. And as for which Key Hash is to be used: You won't have to decide that. Since you will have added both the Key Hashes to your Developer Console, Facebook will use the appropriate one automatically.
  3. I am not aware of needing to add the Key Hash to the Manifest file. It perhaps may be a requirement of the Facebook SDK v3. In such a case, while testing, use the Key Hash created with the debug.keystore and when you are ready to release the App, change to the Key Hash created using your release keystore.

Hope this addresses your question.

EDIT

As Offbeatmammal as already pointed out, you can add multiple Key Hashes to your Developer Console. So storing and using multiple Key Hashes is something you won't have to worry about.