241

In one of my apps I need to get data from Facebook... I am doing this:

I have created app ID. It logs in successfully, but after logging out, I log in, and then it gives me:

Screenshot of invalid key hash error Facebook

What is wrong I am doing? I am using the Facebook SDK... I have installed Facebook on my phone... It is running well within an emulator, but that does not have the inbuilt Facebook application installed.

This is my code:

if (FB_APP_ID == null) {
    Builder alertBuilder = new Builder(this);
    alertBuilder.setTitle("Warning");
    alertBuilder.setMessage("A Facebook Applicaton ID must be " +
                            "specified before running this example: see App.java");
    alertBuilder.create().show();
}

// Initialize the dispatcher
Dispatcher dispatcher = new Dispatcher(this);
dispatcher.addHandler("login", LoginHandler.class);
dispatcher.addHandler("stream", StreamHandler.class);
dispatcher.addHandler("logout", LogoutHandler.class);

// If a session already exists, render the stream page
// immediately. Otherwise, render the login page.
Session session = Session.restore(this);
if (session != null) {
    dispatcher.runHandler("stream");
}
else {
    dispatcher.runHandler("login");
}
CyberStems
  • 326
  • 2
  • 15
Android
  • 8,995
  • 9
  • 67
  • 108
  • You must need to generate keyhash and give that value to your Facebook Developer Account. I think you dont have an idea to generate it..right? – Pratik Dasa May 15 '14 at 09:23
  • go to this for [Best Explanation](https://developers.facebook.com/docs/android/getting-started) – M D May 15 '14 at 09:24
  • 12
    but it runs fine for first time ligin it not working if i am log in after logout done – Android May 15 '14 at 09:29
  • @Pragna have you declare hashkey or not? first let me know – Pratik Dasa May 15 '14 at 09:31
  • 1
    yes i have.. created using try { PackageInfo info = getPackageManager().getPackageInfo( "com.facebook.samples.hellofacebook", 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)); } – Android May 15 '14 at 09:53
  • and that i have put in developer/facebook – Android May 15 '14 at 09:53
  • first time login done and get also i am getting but after logout it says me invalid keyhash – Android May 15 '14 at 09:55
  • 1
    I soved this problem here! Here understanded cool![http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash/12405323#12405323 ][1] – Madi Jul 22 '14 at 05:08
  • Hi am also got the same issuee like after login with facebook showing invalid keyhash.am doing every thing same for keytool and hash key generation i dont know even google maps also showing invalid apikey but am getting hash key that i integrated in developer site – Harsha Sep 21 '15 at 05:39
  • 4
    @Android Even though this is old, but I should mention this. This does not happen when a user logout and then login. This happen when you debug the second time i.e. reinstall the app while debugging. Thus, the hash changes. This doesn't happen in case of signed app(production ready) – Nilay Vishwakarma Apr 02 '16 at 23:34
  • 3
    Do you get the same error if you uninstall the Facebook App? I tested from two phones and this error only occurs when the Facebook App is installed. – Jaime Montoya Feb 24 '17 at 16:00
  • Please look to this link it may help you [Facebook Login for Android App with release key ](https://stackoverflow.com/a/48662606/7108113) – Dinil ps Mar 21 '18 at 07:22

30 Answers30

289

The generated hash key is wrong. You may get the hash key using two steps.

One is through a command prompt. Another one is through coding. The hash key through a command prompt is working on the first time only. I don't know the reason. I have also got the same problem. So I tried it through programmatically.

Follow these steps:

Paste the following code in oncreate().

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("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
}
catch (NameNotFoundException e) {
}
catch (NoSuchAlgorithmException e) {
}

Modify "com.example.packagename" with your package name in the above coding without fail (you may find your package name in the Android manifest file).

Run your application. Go to the activity where you pasted the above code. In the LogCat file, search for "KeyHash". You may find a key hash. Copy the key hash and go to Facebook application dashboard page. Go to settings and enter the details like in the below image.

Enter image description here

Once you finished the above step, relaunch the app again. You may now log into Facebook. For more details about key hash, check the link.

If you add wrong information in the settings page, it means it will give some error. So use the correct information there. And also if the public (other than you) need to use your application means you need to enable the permission (change "yes" in the "Status & Review" next to the setting).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahendran Sakkarai
  • 8,381
  • 6
  • 44
  • 66
  • 21
    By this way, most likely you got a key hash for debug keystore. It works for you in development mode, not necessary works for your production mode. At least, it doesn't work for my production app. – Liangjun Aug 11 '14 at 15:06
  • Hey by this code 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("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); a different hash key is sent while when i ran the command in cmd on windows my hash key was different and i have added it in FB but still the log shows the hash of the programatic code – Sagar Devanga Jul 03 '15 at 11:11
  • I generated the Key Hash through command prompt on the desktop and added to the facebook dashboard, but the error persists... – Sauron Feb 24 '17 at 03:02
  • I have 2 doubts. `One:` Can we delete the above code from `onCreate` method after we note the `Key Hash?` `Two:` Will this `Key Hash` work in `released apps (for apps in playstore)` ? – Nimmagadda Gowtham Feb 13 '18 at 16:28
  • @NimmagaddaGowtham 1. I hope you can. because that block of code is to get the hash key used to built the apk. 2. No it won't work. Because you'll use a different keystore to generate the release apk. so the key hash will be different for that. You need to get the keyhash from the keystore which you used to sign the release apk and add that in the facebook developer site. – Mahendran Sakkarai Feb 14 '18 at 06:36
  • This will give you DEBUG hash key – Konstantin Konopko Apr 14 '18 at 11:57
  • 1
    Saved me a lot of time. Still the best. Check the verbose for the keyhash and copy and paste it in the facebook developers page. Don't make the mistake of typing it manually! Also, understand that keyhash changes everytime you uninstall and install the app. – sanjeev May 22 '18 at 04:22
  • Thanks. It works me. Previously I tried more time in cmd on Windows 11. – Sherzodbek Muhammadiev Jul 06 '22 at 05:06
259

If you are using Google Play App signing:

Open the App signing section in Google Play Console, and get the SHA-1 hash under App signing certificate. Then convert it to Base64, for example with this tool: Hexadecimal -> base64 string decoder

Console screenshot

Convert to Base64 screenshot

Community
  • 1
  • 1
Rafal Malek
  • 3,493
  • 1
  • 17
  • 18
  • 10
    Thank you! It works! You can also use terminal command for it: `echo YOUR_SHA1_CERTIFICATE_COPIED_FROM_GOOGLE_PLAY | sed s/\://g | xxd -r -p | base64` – Yuriy Seredyuk Sep 22 '17 at 09:34
  • If after a while you want to find out what all the keys to those hashes are, this reverses it for me: echo "hash_from_facebook" | base64 -D | xxd -p | awk '{print toupper($0)}' | sed 's/../&:/g;s/:$//' – splatte Dec 11 '18 at 07:27
  • Shall I need to add release key hash or debug hash in the facebook developer account. – sejn Nov 24 '21 at 14:40
  • Thank you so much. After 2 days of searching for a solution. This is the best answer I found't. – alifnaiech Jan 27 '22 at 09:07
140

If you are facing this problem then put this key into your developer.facebook.com:

Enter image description here

Then make sure your app is live on developer.facebook.com.

This green circle is indicating the app is live:

Enter image description here

If it is not then follow these two steps for make your app live:

Step 1 Go to your application→settingadd Contact Email and apply Save Changes.

Step 2 Go to the App Review option and make sure this toggle is Yes. I added a screenshot:

Enter image description here

Note: If you want to copy the hashkey, check the BlueServiceQueue in LogCat.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Arpit Patel
  • 7,212
  • 5
  • 56
  • 67
  • 5
    Is there an easy way to copy that hash from the phone? – Daniels Šatcs Mar 12 '16 at 00:19
  • 5
    @DanielShatz it appears in logcat. I found out only after I copied it letter by letter. – Alaa M. Oct 01 '16 at 18:07
  • 5
    @DanielShatz Look for tag `BlueServiceQueue` in logcat – Alaa M. Nov 26 '16 at 19:15
  • i just enter the keys and it works for me thank you so much – Innocent Mar 21 '17 at 19:45
  • Welcome @innocent – Arpit Patel Mar 22 '17 at 00:54
  • Is the key will get change if the same apk is install in different device?Please let me know already done the copying of the key char by char – blackjack Apr 21 '17 at 09:28
  • @blackjack No i think key will be the same for all mobile what problem you are facing? tell me so i can help. – Arpit Patel Apr 21 '17 at 13:43
  • 1
    @ArpitPatel Thanks for solution It works but I want to know why Facebook showing this hash key error on some devices while the release hash key is correct and what would be the correct solution for this which resolve this issue permanently for future applications – Nooruddin Lakhani Jul 06 '17 at 10:51
  • 7
    This answer worked for me. After some attempts of typing hash manually it gave me same error, the problem was, I typed capital i "I" instead of lower case L "l". Took me some time to realise this. – Markus Oct 23 '17 at 14:02
  • Hi, I have release apk and installed in multiple devices. When I try to login into my application it show's invalid hash key error. I have added that hask key in to my face book developer account it's working fine but when I try to login in my app using fb account in another device again shows invalid hash key error. How can we resolved this issue. – Deepak Nov 29 '17 at 06:15
  • Check your app has green circle in Facebook developer site. If not then You need to live that app in your Facebook developer site. – Arpit Patel Nov 29 '17 at 06:41
  • bad solution... :( – marti_ Mar 14 '18 at 11:12
  • @Osgux Can you tell me what is wrong with my answer and can you tell me what is the good solution for that? – Arpit Patel Mar 14 '18 at 17:32
  • 2
    This is working but Im wondering from where FB get this hash key ? No one wonders ? The error was displaying the good working hash key, but even with all commands, or getting sha1 to base64 from google app signing gave me the key that FB shown in the error ... Thanks for the trick anyway – Umar3x May 12 '18 at 14:09
  • it works but why is that happening. what if it happens for live users? – Emil Jun 05 '18 at 23:41
  • where must I put that cash key. Why nobody asks that? there is no field saying about hash key in the developer.facebook.com – CodeToLife Feb 07 '19 at 14:26
  • I have a doubt. It seems that the hash key keeps on changing. If you're using a multiple device to login with facebook, the error will appear but not happening all the time. – Emerald Feb 20 '19 at 05:06
  • at first i though it will be differ from each phone but. no... just copy the exact hash... for live development – Muhammad Asyraf Jan 13 '20 at 08:36
  • Which key needs to be added in facebook? Does this is release or debug key – sejn Nov 24 '21 at 15:00
100

I got the same problem. I was sure that it was due to very small fault and yes it was!

I found the solution:

When generating the debug hash key in my computer, I entered the password of my system. But the password should be the following -

Enter keystore password: "android". This was the only problem in my case.

----- For generating Debug key hash, use this command -

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Enter keystore password: 'android'

----- To Generate Release key hash, use this command -

keytool -exportcert -alias "alias of keystore" -keystore "Your path to the keystore when signing app" | openssl sha1 -binary | openssl base64

Provide your keystore password after executing this command.

Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42
  • 6
    using "android" as the password works for me. this is puzzling. – adbie Apr 28 '16 at 08:19
  • 3
    use this "android" as a password when generating hash key. – Akash Bisariya May 02 '16 at 07:44
  • android is the password for debug version, probably will not work in release. – Beto Caldas Sep 02 '16 at 02:37
  • yes, In release version you have to put your keystore passsword @Beto Caldas – Akash Bisariya Dec 21 '16 at 14:18
  • 2
    on windows machine, ensure that path variable is properly set for openssl\bin and java..\bin folders. Also set HOMEPATH variable to be able to use commands from facebook. – KawaiKx Apr 26 '17 at 03:20
  • 1
    At least on mac I had to install the Java JDK to get this to work. Otherwise the above debug command still generates a hash, but the hash doesn't work and you won't get prompted for a password. With JDK installed this worked like a charm. – lejonl Jan 08 '18 at 20:10
  • install openssl @KonstantinKonopko – Akash Bisariya Apr 14 '18 at 18:13
  • 1
    Doesnt work anymore. Have tried multiple times with the android password.. fb still complains – AlwaysConfused Jan 12 '20 at 18:10
  • As a comment to this solution - What is important is that you need to have the correct path for: `~/.android/debug.keystore` - debug.keystore should be a file that you have in your project. Running command above it won't tell you that path is wrong (your generated key will be wrong and not the same as in the error you get). That was the problem in my case. – Mieszczańczyk S. Oct 05 '21 at 09:39
  • 1
    magically worked for me, thanks! – Serhii Harbovskyi Dec 15 '21 at 14:58
22

I experienced the same problem. I made a short research on the possible reasons for this strange behavior and I found the following:

  • During the first execution of a new Facebook app, it will allow connection/login even if you don't specify any key hashes.

  • For me, the tutorial which Facebook provided didn't generate the correct key hash, because it was giving the wrong configuration. When executing:

    keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl
    base64
    

make sure you check all properties - the HOMEPATH, the existence of the keystore, etc. Maybe you also have to provide password.

  • What generated the proper configuration was the solution suggested by @Mahendran.

  • Also, if you see the error originally posted (https://i.stack.imgur.com/58q3v.png), most probably the key hash you see on the screen is your real one. If nothing else works, try inputting it in Facebook.

I got all those results with: Windows 7 64-bit edition, Android Studio 1.2.2, JDK 7.

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
Martin Doychev
  • 261
  • 2
  • 4
  • 2
    linux version: ` keytool -exportcert -alias androiddebugkey -keystore $HOME/.android/debug.keystore | openssl sha1 -binary | openssl base64` – ruX Jan 28 '16 at 15:49
  • 2
    Just input whats shown by facebook on device screen, that should work. Thanks for the note @Martin – ralphgabb Feb 14 '17 at 05:26
19

This is how I solved this problem:

First you have to get the SHA-1 value. For that there are two ways.

To get the SHA-1 value in Android Studio.

  1. Click Gradle
  2. Click Signing Report
  3. Copy the SHA-1 value

OR

To get the SHA-1 value from the keystore file.

keytool -list -v -keystore keystore_file_name.jks -alias key0

Copy the SHA-1 value to your clipboard like this:

CD:A1:EA:A3:5C:5C:68:FB:FA:0A:6B:E5:5A:72:64:DD:26:8D:44:84

And open Hexadecimal -> Base64 string decoder to convert your SHA-1 value to Base64.

This is what Facebook requires.

Get the generated hash " ********************= " and copy the key hash to the Facebook app.

Community
  • 1
  • 1
Sajid Zeb
  • 1,806
  • 18
  • 32
15

According Facebook Login for Android, you must provide the key hash value. In order to obtain it, you will need the key used to sign your application.

keytool \
    -exportcert \
    -alias YourKeyAlias \
    -storepass YourStoreKeyPassword \
    -keystore PathToYourKeyStoreFile | openssl sha1 -binary | openssl base64
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JP Ventura
  • 5,564
  • 6
  • 52
  • 69
  • 1
    just want to add a comment, use your production keystore. – Liangjun Aug 11 '14 at 15:20
  • 2
    @Liangjun Actually you should use all your keys because otherwise you won't be able to test Facbeook Login in debug environment. – Pijusn Oct 01 '14 at 11:14
  • 2
    @Pius, yes, I actually use both keys. I should have stated it clearly. – Liangjun Oct 03 '14 at 04:04
  • I get an error for this command (No Java runtime present, requesting install.) but still get a key too, however is invalid and i just copy paste the one from logcat that tells me is not recognised. – Cristi Băluță May 04 '19 at 07:56
8

I tried all of the previous answers and nothing helped my case with my clients!

Then my client remembered he had the Facebook App installed on his device. After he removed it. the login worked perfectly.

The hashkey had been changed, and I've replaced the old hash keys at Facebook Developers Console with the key from the error (as suggested above), and it works!

The Facebook App itself might be the issue, so you better figure this out on a device with the Facebook app installed and on a device with the Facebook app not installed and handle both cases...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matan Dahan
  • 390
  • 5
  • 10
  • Yes same here I got this error after installing facebook app on device. So currently I put 2 hash key on Facebook dev settings. – stuckedunderflow May 03 '17 at 06:17
  • 3
    I have very similar situation to yours. The thing that helped me is go to your FB page - Settings - Apps - Remove the app from the list. Change hash key and reinstall fb app and your app. And now it works... – anna_manzhula Jun 07 '17 at 11:43
8

You must create two key hashes, one for Debug and one for Release.

For the Debug key hash:

On OS X, run:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

On Windows, run:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl
base64

Debug key hashes source

For the Release key hash:

On OS X, run (replace what is between <> with your values):

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

On Windows, use (replace what is between <> with your values):

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

Release key hashes source

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MBH
  • 16,271
  • 19
  • 99
  • 149
  • I get an error for this command (No Java runtime present, requesting install.) but still get a key too, however is invalid and to make it work i just copy paste the one from logcat – Cristi Băluță May 04 '19 at 07:58
  • Maybe you havent set the PATH of your java and keytool in the command line ? @CristiBăluță – MBH May 04 '19 at 13:18
7

Even though this question has been answered in alot of helpful ways I just wanted to add that when I followed Rafal Maleks answer (using the hash keys on Google Play Console) I was NOT able to use the App Signing SHA1 key, still got the generic error from Facebook. Instead I needed to use the SHA-1 certificate fingerprint from the Upload Certificate part (just below the App Signing part on Google Play Console). Same process otherwise;

  1. Copy the SHA-1 certificate fingerprint from Upload Certificate section in Google Play Console

  2. Convert the SHA-1 using: http://tomeko.net/online_tools/hex_to_base64.php and copy the output (base64)

  3. Paste it into the Key Hashes input on developer.facebook.com and save changes.

Hopefully this answer isn't to redundant and will help someone that can't get it to work with the App Signing certificate.

Now Facebook login works in my app both in debug and release mode.

Ferenziz
  • 174
  • 1
  • 6
4

The following code will give you your hash for Facebook, but you have to follow these steps in order to get the release candidate hash.

  1. Copy and paste this code in your main activity

    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("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    }
    catch (NameNotFoundException e) {
    }
    catch (NoSuchAlgorithmException e) {
    }
    
  2. Generate a signed APK file.

  3. Connect your phone to a laptop and make sure it stays connected.
  4. Install and run the APK file in your phone by manually moving the release APK to your phone.
  5. Now look at Android LogCat (use filter KeyHash:). You should see your release hash key for Facebook. Simply copy and paste it in your https://developers.facebook.com/apps. It's under settings.
  6. Now you can test the app it should work perfectly well.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
abdul jalil
  • 136
  • 6
  • note the code only works if you generate signed apk. otherwise it will only give you debug apk hash which is useless for released apk – abdul jalil May 08 '17 at 19:30
  • Hi, when I gave generated hashkey to the facebook app it works fine but when try to run in another device it's again showing 'INVALID HASH KEY' how can I set hash key for the face book contain for work in all devices. – Deepak Nov 28 '17 at 14:48
3

I was having the same problem. First log in, just fine, but then, an invalid key hash.

The Facebook SDK for Unity gets the wrong key hash. It gets the key from "C:\Users\"your user".android\debug.keystore" and, in a perfect world, it should get it from the keystore you created in your project. That's why it is telling you that the key hash is not registered.

As suggested by Madi, you can follow the steps on this link to find the right key. Just make sure to point them to the keystore inside your project. Otherwise you won't get the right key.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

If you are typing the keyhash manually (for example from mobile to the Facebook Dashboard), make sure to differentiate between small L and capital I.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kashif Nazar
  • 20,775
  • 5
  • 29
  • 46
2

After a long research, we found a solution.

We had set permissions as:

loginButton.setReadPermissions(public_profile email);

This worked for the first time, but when we re-logged in to Facebook, it gave the Invalid Hash Error.

The simple solution was to change the above line to:

loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));

And it worked like a bliss!

Facebook should return the correct exception instead of the misleading invalid hash key error.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
2

After so many trials I stumbled on a solution to this. I generated and added both debug and release keys to the Facebook developer console and still got the error.

The only solution that worked for me was is to uninstall the OpenSSL program from Google and download from Win32/Win64 OpenSSL Installer for Windows

It really works like magic.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Uchenna Nnodim
  • 458
  • 4
  • 11
2
try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "www.icognix.infomedia",
                           PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("YourKeyHash: ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        Log.d("YourKeyHash: ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
}
catch (PackageManager.NameNotFoundException e) {
}
catch (NoSuchAlgorithmException e) {
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zafar Hussain
  • 264
  • 2
  • 10
1

Paste the following code into your OnCreate method:

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("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
}
catch (NameNotFoundException e) {
    e.printStackTrace();
}
catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
}

Just modify the package name. Then go to your LogCat file and select Debug search here. Then you will find the hash key. Now copy this hash key and then go to the developer.facebook.app_id site, edit your hash key, and press Save. Now run your Android project again. I think issue will be resolved.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
pavel_coder
  • 181
  • 2
  • 5
1

This may help someone with the same problem.

  1. Generate the key hash using the below code

    keytool -exportcert -alias <your_keystore> alias -keystore <your_keystore_file> | openssl sha1 -binary | openssl base64
    

    How to use keytool

  2. Paste it in required field in Facebook developer

  3. In Android Studio, menu FileProject Structure

    Enter image description here

    Add signing parameters.

  4. Select flavors

    Enter image description here

    Select the signing configuration we created.

  5. Select build type

    Enter image description here

  6. Select build variant and build it

    Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CLIFFORD P Y
  • 16,974
  • 6
  • 30
  • 45
1

I had the same problem when I was debugging my app. I've rewrote the hash that you have crossed out in the attached image (the one that Facebook says is invalid) and added it in the Facebook's developers console to key hashes. Just be careful of typos.

This solution is more like an easy workaround than a proper solution.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Piotr Sagalara
  • 2,247
  • 3
  • 22
  • 25
1

I saw many people giving difficult answers, the to the point answer through which I fixed my issue is just go to the project/android folder/app using terminal, this is where your debug.keystore file is

keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64

copy and paste this command, replace the alias and used the same password which is in your project/android/app/build.gradle

debug {
  storeFile file('debug.keystore')  
  storePassword 'android'
  keyAlias 'androiddebugkey'      <---- alias
  keyPassword 'android'           <---- password
}
Bilal Yaqoob
  • 790
  • 1
  • 10
  • 22
0

What Facebook used is not the default password and alias for debug. You need to change it following and it will work.

/usr/lib/jvm/jdk1.8.0_66/bin/keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

If you have not changed anything with the default password it should be "android".

You can also configure it in the build.gradle file. But the same alias password should be used for generating the hash:

android {
    signingConfigs {
        release {
            storeFile file("~/.android/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
abhi shukla
  • 1,119
  • 1
  • 10
  • 19
0

Here are a lot of right answers. Just one thing:

Paste the received hash into ApplicationSettingsMain, not via the fast start tutorial.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VKostenc
  • 1,140
  • 14
  • 19
0

I had the same problem.

Make sure that you build the APK file with the same device that generated the hashkey which is stored on in the Facebook developers section.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
genericname
  • 167
  • 3
  • 11
0

I fixed this by adding the following into MainApplication.onCreate:

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "com.genolingo.genolingo",
                           PackageManager.GET_SIGNATURES);

    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
        KeyHash.addKeyHash(hash);
    }
}
catch (PackageManager.NameNotFoundException e) {
    Log.e("PackageInfoError:", "NameNotFoundException");
}
catch (NoSuchAlgorithmException e) {
    Log.e("PackageInfoError:", "NoSuchAlgorithmException");
}

I then uploaded this to the Google developer console and then downloaded the derived APK which, for whatever reason, has a totally different key hash.

I then used LogCat to determine the new key hash and added it Facebook as other users have outlined.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael
  • 2,258
  • 1
  • 23
  • 31
0

If you're generating release key hashes, make sure you enter the actual password of your keystore and not "android".

This was my issue. Debug release was working, but the release APK was not.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sermilion
  • 1,920
  • 3
  • 35
  • 54
0

I also had the same problem. What solved the problem is adding the hash on the screen to my app.

Anthonio
  • 56
  • 2
0

I am sorry to say but nothing actually worked for me. Finally what helped me is get the upload SHA-1 certificate fingerprint from google play console and convert it to base64 and adding it to facebook. If anyone need help please comment

user2462948
  • 87
  • 1
  • 5
0

I solved this problem by changing the phat of the debug.keystore, the correct phat must be the phat of your Android project file. Like this:

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\yourUser\Documents\other\yourProjectName\android\app\debug.keystore" | "C:\openssl\openssl-3\x64\bin\openssl" sha1 -binary | "C:\openssl\openssl-3\x64\bin\openssl" base64

if you don't know how to get the phat of openSSL I recommend you this video on youtube: https://youtu.be/aZlkW3Evlx4

DrDaxter
  • 11
  • 5
0

To get the SHA1 key hash for your Facebook Android app, you will need to first generate the SHA1 value from your keystore file. You can do this by running the following command in a terminal:

keytool -list -v -keystore keystore_file_name.jks -alias key0

This will output the SHA1 value to the console. You can then copy the SHA1 value to your clipboard.

Next, you will need to convert the SHA1 value to base64. You can do this by visiting the following website:

http://tomeko.net/online_tools/hex_to_base64.php

Paste the SHA1 value into the input field and click on the "Convert" button. This will generate the base64-encoded SHA1 value.

Finally, you will need to copy the base64-encoded SHA1 value to your Facebook app. You can do this by going to the "Settings" page in your Facebook app and adding the key hash to the "Key Hashes" field.

Once you have added the key hash, your Facebook app will be able to communicate with the Facebook servers.

-1

Use the below code in the onCreate() method of your activity:

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "your application 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) {
}

Run this code. This will generate the hash key. Copy this KeyHash in the Facebook application setting, and save changes. Then log into your application. This will work perfectly in the future too.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ashutoshg
  • 157
  • 1
  • 7