2011-06-26 56 views
14

我只想要一些确认。使用Android Facebook SDK的keytool

我开发上我试图向Facebook整合到一个应用程序窗口

和SDK文档说我需要“导出签名”

从这里:http://developers.facebook.com/docs/guides/mobile/#android

所以它说,运行此命令:

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

首先我不得不下载的OpenSSL:OpenSSL

现在上面的命令,我认为应该转换为:

"C:\path\to\java\keytool" -exportcert -alias your_alias -keystore "C:\path\to\your\keystore\keystore.name" | "C:\path\to\openssl_install\bin\openssl" sha1 -binary |"C:\path\to\openssl_install\bin\openssl" base64 
  • 所以,你要被安装在最新版本的Java安装文件夹的密钥工具?
  • 你想让别名成为你在eclipse中创建正常apk文件的别名的名字吗?
  • 您希望keystore成为您在导出android应用程序时使用的密钥存储区?
  • 你想的OpenSSL是你刚安装

所以一旦我做到了这一点,它要求输入密码之一:(它显示为我打字它的密码)

如果我输入正确的密码,我得到

'zR2tey1h9kqPRSW/yEYEr0ruswyD=' (changed for public)

但如果我输入的密码不正确仍然会返回我的

'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='?

形式的代码0

所以,是的,只是在寻找一个确认,我做正确的事情,这就是输出预计

+0

好博客解释一些陷阱:http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/ – Blundell

+0

您是否使用'android'作为密钥库的密码? –

回答

1

代码是要在正确的方式我也think.i执行该命令,并把这个哈希在我的FB的应用程序和它的作品做正确的。

12

的最好的方式得到你的哈希值是通过运行下面的代码:

try { 
      PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 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)); 
        Log.e("hash key", something); 
     } 
     } 
     catch (NameNotFoundException e1) { 
      // TODO Auto-generated catch block 
      Log.e("name not found", e1.toString()); 
     } 

      catch (NoSuchAlgorithmException e) { 
       // TODO Auto-generated catch block 
       Log.e("no such an algorithm", e.toString()); 
      } 
      catch (Exception e){ 
       Log.e("exception", e.toString()); 
      } 

当用windows cmd,git bash或cygwing终端提取散列时,三种工具会给出不同的结果。

最准确的是上述

+0

@Mina该Base64类的导入是什么? – Blundell

+0

它包含在Android 2.2中,如果您使用的是较低版本,则使用2.2构建应用程序,运行代码并获取散列,然后根据您的初始目标构建应用程序。 –

+0

嗯现在我更加困惑,因为这给了我一个不同的哈希代码给我使用我的问题方法 – Blundell

0

回答以下你的问题:

So once I've done this it asks for a password: (it shows the password as I'm typing it)

If I enter a correct password I get

'zR2tey1h9kqPRSW/yEYEr0ruswyD=' (changed for public) but if I enter an incorrect password it still returns me a code in the form of

'ga0RGNYHvTR5d3SVDEfpQQAPGJ1='? So yeah, was just looking for a confirmation that I'm doing the right thing, and this is the output expected

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64具有三个命令供给上述命令到下面的命令的输出。

  1. keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore
  2. openssl sha1 -binary
  3. openssl base64

当不正确密码密钥库中给出,第一命令生成错误,但不会被显示为将被输入到第二个命令和不同的散列生成。只运行第一个keytool命令(keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore)确认您的密钥库密码,如果它是正确的。如果密码不正确,将显示类似于下面的输出。

> keytool -exportcert -alias androiddebugkey -keystore 

〜/ .android/debug.keystore 输入密钥库密码:
的keytool错误:java.io.IOException异常:密钥库被篡改,或密码不正确

提供的Android到回答为Enter keystore password:提示如果android调试哈希生成。 Android的调试密钥库的默认密码是安卓

司令部也已经写了可以捕捉到keytool命令错误,看看是否命令1以上运行命令2.

So you want the keytool that is installed in your latest Java install folder?

You want the alias to be the name of the alias you use for a normal apk creation in eclipse?

You want the keystore to be the one you use when exporting android apps?

You want openssl to be the one you just installed?

是所有的问题之前,返回错误。可以将PATH设置为不输入keytool和openssl的完整路径。