Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnknownError: ApiException:Key hash **** does not match... when I have FB app installed

I will note first I am very new to java and android development and possible could have missed something simple. I working through the Facebook example "sessionlogin." It works while there is no Facebook app. When I install the Facebook App and try to run the code it fails with the error

UnknownError: ApiException:Key hash BGyx5d0rMOuY9aQqZK4B9q04+no does not match any stored key hashes

The first thing that I concluded was the obvious the keys are not match, but why? I am confused as to why the app would work without and what the difference in the hash key is for the FB app? Does it use my app's key? Does the FB app require a signed app to access its data?

As for the some of the things i have done, I added a snippet of code to output the hash key at the start of the app. In all cases BGyx5d0rMOuY9aQqZK4B9q04+no= was displayed. The app was stuck in debug mode, so I signed and published the app as explained in this solution. In return the hash that I was using was egNzXZN1fDDeK7PNL+QzHDAKUsg= (on FB, returned from the console cmd ln) but the snippet was returning BW0xQ5kipPoWYWWJd1g3yaKCe6M= when the app actually ran.

After reading through dozens of articles and working through about half of those, I've lost lots of time trying to learn what I am doing wrong and I am now, completely clueless. How can get a working example? Am I missing some fundamental configuration?

Details:

  • java 7 release 25
  • win 8 64bit
  • ADT (eclipse)
like image 674
samuel.molinski Avatar asked Oct 24 '13 21:10

samuel.molinski


People also ask

How do I change the key hash on Facebook?

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...


1 Answers

From the troubleshooting section of this guide, add this to your onCreate:

try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    "com.mypackage.name", 
                    PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
        } catch (NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

Add the keyHash shown as is. It will be very similar to the one in your error log but with / & - replaced

like image 65
kakoma Avatar answered Nov 14 '22 23:11

kakoma