I'm a 27 year old software developer that mainly focuses on software development. As everyone i have taken a side in the Apple vs Android game. My choice is Android because of oh so many reasons :-) By contributing to the Android developers content online ( in the form of writing Android tutorials ), I hope to convince others to make the same decision and help them make nice content for the Android platform. Mark is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

Implementing Facebook into your App: invalid key with keytool

  • submit to reddit

I recently had an annoying error. I wanted to implement some "Post to Facebook" functionality to my application and i got an error saying that my key vas invalid...

Facebook unique hash error

Facebook unique hash error


To implement this I just followed the official implementation of the SDK and after a quick search it seems that its is a problem that more developers run into.

I found the answer to my problem on StackOverflow. Mr. Omsn just makes the key that the Facebook API wants from within your application.

Here is a quick code snippet:

try {
   PackageInfo info = getPackageManager().getPackageInfo("**YOURPACKAGENAME**", PackageManager.GET_SIGNATURES);
   for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        Log.i("PXR", Base64.encodeBytes(md.digest()));
catch (NameNotFoundException e) {}
catch (NoSuchAlgorithmException e) {}

Only thing you need is 1 extra class (Base64) to get this working. I used this one.

one other thing i changed is the application type to "Native App" in the Facebook application registry.

I made a simple Eclipse project that prints the key to the LogCat window. I hope this helps you guys, whenever you run into this problem.

Edit: this appears to be a Windows problem. You can also install Cygwin and run the keytool command in the Cygwyn shell

Published at DZone with permission of Mark Mooibroek, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)