Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Implementing Facebook into your App: invalid key with keytool

DZone's Guide to

Implementing Facebook into your App: invalid key with keytool

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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");
        md.update(signature.toByteArray());
        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

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Published at DZone with permission of Mark Mooibroek, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}