如何创建Facebook密钥哈希?

问题描述:

在Facebook的Android的教程中,我们被告知要使用下面的代码来创建密钥散列:如何创建Facebook密钥哈希?

密钥工具-exportcert -alias androiddebugkey -keystore〜/ .android/debug.keystore | openssl sha1 -binary | openssl base64

这是在所有情况下使用的确切代码吗?例如,而不是~/.android/debug.keystore应该像C:/folderone/foldertwo/.android/debug.keystore

正如你所看到的,我不确定是否需要引号括起来,是否需要完整的路径!

有人能够提供真实世界的例子吗?


https://developers.facebook.com/docs/mobile/android/build/#sso

+0

你需要有来自谷歌的OpenSSL ...遵循[链接]给出的步骤[1] [1]:http://*.com/questions/4388992/key-hash- for-android-facebook-app/6665263#6665263 – 2012-04-06 10:12:56

+0

你可以在这里看到真实的例子http://*.com/questions/9977492/android-facebook-sdk-keystore-not-asking-or-password/10026147#10026147 – dimetil 2012-04-06 10:40:40

+0

您应该找到答案由Avi [here。](http://*.com/a/6665263/5861880) – abosamy 2017-03-02 15:03:24

在Eclipse中,窗口 - >喜好 - >Android的 - >构建 - >默认的调试密钥库,复制路径替换~/.android/debug.keystore

你可以这样创建

keytool -exportcert -alias androiddebugkey -keystore c:\Users\<your windows default user>\.android\debug.keystore | openssl sha1 -binary | openssl base64 

输入密钥库密码:安卓

+0

链接已死 – larham1 2013-05-03 16:52:27

+0

此处稍作更改。首先,如果您的openssl.exe不在PATH中,您将无法以此方式调用它(keytool也是如此)。其次,最后一部分是“openssl base64”。 – Asim 2013-09-17 04:56:03

+0

MacOS:keytool -exportcert -alias androiddebugkey -keystore〜/ .android/debug.keystore | openssl sha1 -binary | openssl base64 密码:android – 2016-11-08 23:17:48

我有同样的问题,我花了几个小时找到一个解决方案,但实际上Facebook的SDK本身提供了解决方案。

在DialogListener类

我修改onFacebookError方法:

@Override 
public void onFacebookError(FacebookError error) { 
    Log.d("myTag",error.getmessage); 
} 

执行应用程序(其是符号用相同的密钥i使用的市场),以及上的logcat将这个标记与下一个消息正确的钥匙。

我们还创建了一个简单的项目,完成所有工作,并在警告框和LogCat上返回正确的密钥。你可以在our blog找到它。

尝试

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

} catch (NoSuchAlgorithmException e) { 

} 

在主要活动:-)这是我的作品为Android SDK 3.0

+1

包含必需:import android.content.pm.PackageInfo;导入android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException;导入android.content.pm.Signature;导入android.util.Base64;导入android.util.Log; – Alireza 2016-05-02 23:31:04

密钥工具-exportcert -alias androiddebugkey -keystore “debug.keystore路径” 唯一的解决办法| openssl sha1 -binary | OpenSSL的BASE64

如果你还没有设置环境变量打开SSL和Java SDK的不是把JDK的到位密钥工具和bin文件夹路径的OpenSSL的路径到位的OpenSSL,不要忘记把双引号为您的路径

ex - “C:\ Program Files \ Java \ jdk1.5.0_11 \ bin”-exportcert -alias androiddebugkey -keystore“C:\ Users \ amin.android \ debug.keystore”| “F:\ openssl \ binsha1 \ openssl.exe”-binary | “F:\ OpenSSL的\ binsha1 \ OpenSSL的。EXE”的base64

/** 
    * Generates the hash key used for Facebook console to register app. It can also be used for other sdks) Method copied from: https://developers.facebook.com/docs/android/getting-started/ 
    */ 
    public static String printHashKey(Context ctx) { 
     // Add code to print out the key hash 
     try { 
      PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES); 
      for (Signature signature : info.signatures) { 
       MessageDigest md = MessageDigest.getInstance("SHA"); 
       md.update(signature.toByteArray()); 
       return Base64.encodeToString(md.digest(), Base64.DEFAULT); 
      } 
     } catch (NameNotFoundException e) { 
      return "SHA-1 generation: the key count not be generated: NameNotFoundException thrown"; 
     } catch (NoSuchAlgorithmException e) { 
      return "SHA-1 generation: the key count not be generated: NoSuchAlgorithmException thrown"; 
     } 

     return "SHA-1 generation: epic failed"; 
    } 

一个蛮力选择是先走一步,尝试从您的应用程序共享的东西。我的应用程序,然后会显示一个Facebook页面,它试图匹配的关键。然后,你可以复制此键,把它放在你的Facebook的“设置”页面上的开发者的Facebook帐户。

不理想,但在紧要关头,它可能会有所帮助。

具有日志中的错误时,尝试登录时Facebook,寻找如下的东西:

Invalid key hash. The key hash *** does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/565561836797777 

其中“***”是您需要使用的关键。