App要使用Facebook 分享時,設要在Facebook應用程式裡設定app 的key hash

但keyhash要怎麼取得呢?

 

 

需下載 openssl

 

下載後,解壓縮,如下,到bin資料下底下取得openssl.exe

C:\Users\Tom\Downloads\openssl-0.9.8h-1-bin\bin

 

放至Java目錄下,如下

C:\Program Files\Java\jdk1.6.0_23\bin

 

並從eclipse取得keystore放置位置

[Windpw] -> [Preferences] -> [Android] -> [Build]  的 Default debug keystore

我這邊取得的是

C:\Users\Tom\.android\debug.keystore

 

再來是使用Java bin底下的keytool,取得keyhash

 

打如下的指令

keytool -exportcert -alias androiddebugkey -keystore C:\Users\Tom\.android\debug.keystore | openssl sha1 -binary | openssl base64

 

會顯示以下,並輸入預設密碼android

輸入keystore 密碼:android

 

就會取得keyhash

再到facebook ->管理應用程式 ->自己的應用程式-> 設定 ,key hash 填入該keyhash即可。

 

debug.keystore的預設資料如下

Keystore name: "debug.keystore"

Keystore password: "android"

Key alias: "androiddebugkey"

Key password: "android"

CN: "CN=Android Debug,O=Android,C=US"


 


所以密碼才填android


 


注意:

打不到的alias及密碼,都會影響keyhash的產生結果,必須與當時的alias及密碼相同。

 

// mac平台

  1. First open a terminal (open a command prompt in windows).
  2. Navigate in the terminal to the directory where your Android debug.keystore is stored.
  3. Mostly it will located under “/Users/user_name/.android/” (In Windows will be C:\Documents and Settings\.android).
  4. Once you are in the “.android” directory, run the following command.
    keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
  5. When it prompts you for a password, type android and hit Enter
  6. Copy the value printed in the terminal that ends with an “=” and paste it in the Key Hash field in Facebook. Then click the Save Changes button.