[Android] Facebook Authentication Error: com.facebook.FacebookOperationCanceledException: remote_app_id does not match stored id
During Android app development, I encountered an error where Facebook authentication failed.
com.facebook.FacebookOperationCanceledException: remote_app_id does not match stored id
This type of error seems to occur when the Key Hashes registered in the Facebook app settings screen are incorrect.
Add the following code to onCreate to output the key hash to the log for verification.
try {
PackageInfo info = getPackageManager().getPackageInfo("com.example.packagename",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("YOURHASH KEY:",
Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
There’s also a method to check the key hash from the command line, but it seems you need to use Windows OpenSSL, as Mac OpenSSL apparently can’t retrieve the correct key hash.
For example, when checking the key hash of debug.keystore using keytool from the command line, the result is bvfSSDnrryuK8cbfekyHTs59l/A=.
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
Enter keystore password: android
bvfSSDnrryuK8cbfekyHTs59l/A=
However, when outputting the key hash from the app execution log using the method at the beginning, it’s dkgthMwGADFQ7/9fkMn4MUzpSWo=, which is the correct value.
It’s a bit confusing, but I’m glad I found the solution.
That’s all from the Gemba.