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 346 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 .
  • AngularJS $watch() , $digest() and $apply() August 26, 2014
    This new text in my AngularJS tutorial explains the $scope functions $watch() , $digest() and $apply(). These functions are the core of the AngularJS data binding system.
  • AngularJS $scope Hierarchy August 19, 2014
    This small addition to my AngularJS tutorial explains the AngularJS $scope hierarchy.
  • CSS Gradients Tutorial August 12, 2014
    You can fill HTML elements with gradients using CSS 3. The browsers and W3C have finally reached a shared standard syntax which is supported by IE, Chrome (Windows + Android) and Firefox.

my tweets

  • দশটি বই আলাদা করা একটু বেশিই কঠিন। সুতরাং আমি ঠিক করলাম যে বই গুলো আমার ছোটবেলাকে চমকপ্রদ করেছে, চোখ ঢুলু... fb.me/1BbjRV8Gt 3 days ago
  • A large system is one where you do not know that some of its component even exist. --Martin Odersky 3 weeks ago
  • reading After the Prophet: The Epic Story of the Shia-Sunni Split in Islam 3 weeks ago
  • i've got itchy feet and been having this itch lately to try out some new languages. #Scala probably the most... fb.me/73AJjLzke 3 weeks ago
  • I added a video to a @YouTube playlist youtu.be/UmW_dSSjCec?a the tipping point 1 month ago
Follow

Get every new post delivered to your Inbox.

Join 346 other followers