最近在弄 Android 版的 Facebook API,結果登入程式都弄好了,就是一直取不到 Token
查來查去,用了
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | "D:\android-develop\openssl\bin\openssl.exe" sha1 -binary | "D:\android-develop\openssl\bin\openssl.exe" base64
或是直接產生自己的 Key 都無法成功,後來如果用程式產生的 Hash Key 就成功了
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.your.package",
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) {
}
特此筆記一番!
查來查去,用了
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | "D:\android-develop\openssl\bin\openssl.exe" sha1 -binary | "D:\android-develop\openssl\bin\openssl.exe" base64
或是直接產生自己的 Key 都無法成功,後來如果用程式產生的 Hash Key 就成功了
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.your.package",
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) {
}
特此筆記一番!
留言
張貼留言