I am building an app which requires facebook login and authentication.
I am following
https://developers.facebook.com/docs/android/getting-started#create-app
I got this error: when I hit the facebook login button:
Multiple posts say that this code should resolve the error
Key hash doesn't match while facebook login in android
:
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.hitup.hitup",
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)
{
}
however the toByteArray() method cannot be resolved!
How can I resolve this error and achieve the simple facebook login for my app?
You must import a android.content.pm.Signature
and not a java.security.Signature
.
from Logcat you can get hash key of facebook please do copy from logcat which having Logcat tag "KeyHash" and put it in your project on developer.facebook site
import android.content.pm.Signature;
try {
PackageInfo info = getPackageManager().getPackageInfo(
**"do not forgot to your package name"**, 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) {
}
OR
1. for Android default keystore : add this to in your terminal
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
2. for signed keystore
keytool -exportcert -alias aliasname -keystore keystorename | openssl sha1 -binary | openssl base64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With