A window appears with the entrance to Facebook and when you click continue to arise an error
SERVER_ERROR: [code] 1349195 [message]: the key hash does not match any of the saved hashes
login() async {
final facebookLogin = new FacebookLogin();
final result = await facebookLogin.logInWithReadPermissions(['email']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
print(result.accessToken.token);
Navigator.of(context).pushReplacementNamed('/home_screen');
break;
case FacebookLoginStatus.cancelledByUser:
print('CANCELED BY USER');
break;
case FacebookLoginStatus.error:
print(result.errorMessage);
break;
}
}
Go to the Facebook Developer site. Log into Facebook and, using the dropdown menu in the top-right, go to Developer Settings: In your developer settings, select Sample App from the menu, and add and save your key hash into your profile: You can add multiple key hashes if you develop with multiple machines.
Go to your output apk files (Usually <project_root>\build\app\outputs\flutter-apk
).
Use keytools to get the SHA1 value (run in terminal / git bash):
keytool -printcert -jarfile app-debug.apk
Convert the HEX value to base64 to get value that ends with =. (i.e. Use this site. Be aware to have at Input type
selected Hex
. And delete all :
between SHA1 key groups -> AB:CD:EF
= wrong, but ABCDEF
= correct)
Update that value to key hashes under your android platform.
This is how I generated facebook keyhash for android build
FlutterActivity
import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Base64
import android.util.Log
import io.flutter.embedding.android.FlutterActivity
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
printHashKey(this@MainActivity)
}
fun printHashKey(pContext: Context) {
try {
val info: PackageInfo = pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val hashKey = String(Base64.encode(md.digest(), 0))
Log.i("MainActivity", "printHashKey() Hash Key: $hashKey")
}
} catch (e: NoSuchAlgorithmException) {
Log.e("MainActivity", "printHashKey()", e)
} catch (e: Exception) {
Log.e("MainActivity", "printHashKey()", e)
}
}
}
Alernative Solution :-
Run this command in the terminal to generate debug key
How to generate Facebook hash key
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | 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