为什么我得到不同的键盘注册Facebook应用程序? [英] Why do I get different keyhashes for registering facebook app?

查看:131
本文介绍了为什么我得到不同的键盘注册Facebook应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过

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

我得到一个keyhash 1knQ67Fx4PUOYXggSe + mnzqaTL8 =



但是谷歌自己的文档建议一个替代方案

  try {
PackageInfo info = getPackageManager()。getPackageInfo(
com.facebook.samples。 hellofacebook,
PackageManager.GET_SIGNATURES);
(签名签名: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){
}

但这会产生 UR02fNgzyMOjpWCxUnjGZ4ctF6Y = 。我已经双重验证,并且我通过各自的方法得到这两个值。



为什么它们不同?我应该在developers.facebook.com注册哪一个?文档看起来不是很清楚。



编辑:



由于Offbeatmammal表示我可以在Facebook网站注册多个密钥。没关系但是我也应该在应用程序清单文件中指定keyhash。 另外询问:应用程序中应该使用哪一个?我可以尝试一下,但答案也是可以接受的。

解决方案

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



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



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



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


  1. < a href =https://stackoverflow.com/a/13283088/450534> https://stackoverflow.com/a/13283088/450534

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

  3. https://stackoverflow.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://stackoverflow.com/a/13283088/450534
  2. https://stackoverflow.com/a/13343529/450534
  3. https://stackoverflow.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.

这篇关于为什么我得到不同的键盘注册Facebook应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆