Code Explosion

Code That Explodes Conventions (In daily life as a programmer I meet problems. This blog where I record them (and more importantly their solutions) so that I can dig them in the future.)

Add your app’s signature to the Facebook App Settings (Alternative Approach)

While developing android apps for Facebook, Facebook requires additional layer of security for mobile apps in the form an application signature. Using keytool that comes with Java JDK, I found difficulties; I couldn’t make it somehow. But I found way to get the hash key. Here is the alternative way to get the hash key.


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Base64;
import android.util.Log;

public class Util {
private Context context;

public Util(Context context) {
this.context = context;
}

public void genHashKeyForFacebook() {
PackageInfo info;
try {
info = context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;

md = MessageDigest.getInstance("SHA1");
md.update(signature.toByteArray());
String hash = new String(Base64.encode(md.digest(), 0));
Log.e("hash key", hash);
}
} catch (NameNotFoundException e) {
Log.e("name not found", e.toString());
}

catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
}
}

Call this method genHashKeyForFacebook() from your activity; you will find the hash key in your LogCat verbose.

app's signature

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on March 17, 2012 by in Android, facebook, Tips and tagged .

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 343 other followers

RSS Jenkov.com

  • SVG Compressed
    My recently published Kindle book, SVG Compressed, has received some great reviews already. 4 reviews with 5 stars. Not a bad start, but this is also my longest book so far, and it is available for only $0.99 on Amazon, so you get a lot for the money!
  • jQuery Compressed - 2nd Edition
    I have updated my Kindle book, jQuery Compressed 2nd edition, to be compatible with jQuery 1.11.0 and 2.1.0 .
  • CSS Media Query Tutorial July 28, 2014
    I have added a short tutorial about CSS media queries to my CSS tutorial trail. Media queries enable you to apply different CSS rules depending on the device that views your HTML page.
  • Open SSL for Web Servers July 25, 2014
    This new tutorial explains how use OpenSSL to create a private key and certificate signing request, and finally how to get a certificate, for use with SSL / TLS / HTTPS on a web server.
  • Nginx Tutorial July 24, 2014
    I have started a tutorial about Nginx, the high performance web server. So far the tutorial covers how to install Nginx on Ubuntu, how to start it, restart it and where to find the configuration files. This tutorial will be updated in the future with information about using Nginx as reverse proxy, configuring SSL and more.

my tweets

Follow

Get every new post delivered to your Inbox.

Join 343 other followers