转自:http://www.dotblogs.com.tw/newmonkey48/archive/2014/04/17/144779.aspx
App要使用Facebook 分享時,設要在Facebook應用程式裡設定app 的key hash
但keyhash要怎麼取得呢?
可參考兩個網址
http://blog.changyy.org/2011/05/android-facebook-sdk.html
http://blog.rx836.tw/blog/android-facebook-key-hashes/
需下載 openssl
http://blog.rx836.tw/blog/android-facebook-key-hashes/
下載後,解壓縮,如下,到bin資料下底下取得openssl.exe
C:UsersTomDownloadsopenssl-0.9.8h-1-binin
放至Java目錄下,如下
C:Program FilesJavajdk1.6.0_23in
並從eclipse取得keystore放置位置
[Windpw] -> [Preferences] -> [Android] -> [Build] 的 Default debug keystore
我這邊取得的是
C:UsersTom.androiddebug.keystore
再來是使用Java bin底下的keytool,取得keyhash
打如下的指令
keytool -exportcert -alias androiddebugkey -keystore C:UsersTom.androiddebug.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"
注意:
打不到的alias及密碼,都會影響keyhash的產生結果,必須與當時的alias及密碼相同。
// mac平台
- First open a terminal (open a command prompt in windows).
- Navigate in the terminal to the directory where your Android debug.keystore is stored.
- Mostly it will located under “/Users/user_name/.android/” (In Windows will be C:Documents and Settings.android).
-
Once you are in the “.android” directory, run the following command.
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
-
When it prompts you for a password, type android and hit Enter
-
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.