I’ve just been following this tutorial, and almost like any other, doesn’t really explain how to generate the keyhash. Fortunately, I managed to generate one and using the “release-signing.properties” file in “platforms\android” I’ve managed to get it to output a android-release.apk. Then, with the hash key that was generated, I copied and pasted it into my Facebook App “Key Hashes” textbox and saved it.
In the command prompt (I’m using Windows) I did… “ionic run android --release” which compiled a release copy of the app and installed it on my phone for testing. It works fine but for some reason, the facebook authentication says “Key hash xxxxxxxxxxx= does not match any stored key hashes” which displays a completely different Key Hash in the error message than the one I generated my self.
I then copied that Key Hash text into my Facebook App settings. Afterwards I edited the “release-signing.properties” to point to the Key Store file created just before, then ran the “ionic run android --release” command which still gave me the error on facebooks authentication of an invalid Key Hash stored.
EDIT: I found the solution. I was using Google’s OpenSSL that seemed to keep giving me a different hash. I came across a StackOverflow thread and read the last comment which seemed to indicate this, and that the solution was to download OpenSSL from here, which solved my problem.
which is the same as what you just posted - so not sure what’s going wrong. Maybe you could try doing a build command instead of run and install it manually, but it sounds like it should be working. Have you double checked you’re referencing the correct Facebook App in your code as well? That might explain the different key hash.
@Crash
This is how i solved this problem
Downloaded your APK to your PC in java jdk\bin folder
C:\Program Files\Java\jdk1.7.0_79\bin
go to java jdk\bin folder and run cmd then
copy the following command in your cmd
keytool -list -printcert -jarfile apkname.apk
Copy the SHA1 value to your clip board
like this CD:A1:EA:A3:5C:5C:68:FB:FA:0A:6B:E5:5A:72:64:DD:26:8D:44:84
and open http://tomeko.net/online_tools/hex_to_base64.php to convert your SHA1 value to base64. This is what Facebook requires
get zaHqo1xcaPv6CmvlWnJk3SaNRIQ= as our keyhash.
Hi @nitishrajput01 : Thank you. The above solution worked fine for me. I just wanted to know how to handle this case on taking a release build ? Can I follow the same method or should I go with keytool -exportcert -alias ALIAS_HERE -keystore path/to/mykey.keystore | openssl sha1 -binary | openssl base64 and copy paste the hashkey generated to facebook settings ?
My question is how does the hash key get into the ionic build android and ionic run android ? Where does the hash key have to be located in order for my project to find it. Am I running the keytool from project root and thus would create a keystore in my project root?
Once I have the keystore created, get the key exported into FB is not a problem…its just knowing where the hash is actually being compiled in my project. There seems little documentation on this subtle detail.
My FB login is working…which makes me think somehow my hash key is correctly being compiled and matches the one I copied to FB…however I continue to get a FB error page when trying to actually post something to a users page with showDialog using method: 'feed' …the error page is a generic “sorry, something went wrong” and then returns a “4201 - user cancelled dialog” to my app when the FB error page is closed.
@joshmorony - creating the hash key and exporting/copying it into FB is no problem. But how is the hash key making it into the ionic app? Do we need to specifically add it to the app…is it auto included (how and where)? If the hash is not in the app, then how does it match whats been copied to FB?
I finally figured it out. The docs are slim at best on this subject.
By default, ionic/cordova uses the %HOME%.android\debug.keystore hash key during development builds (ie: ionic build android). This is the DEVELOPMENT key you need to extract and add to the FB Android app profile. The default password for this debug.kestore (for both store and key) is android.
When you compile your app for publication, you create your own keystore and reuse that key during the final android compile process (before submitting to store). You will need to add this hash key to the FB Android app profile too. This is the PRODUCTION key.
Both keys should be added to the FB Android app profile…if you ever have to change a key, then the FB app profile must be updated too. Probably best just to add another key versus deleting the old…if you delete the old one and users are on older versions of your app, then deleting the old key will prevent those users from interacting with FB.