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 .
  • CSS Transitions October 13, 2014
    Text no. 29 in my CSS tutorial is about CSS transitions which enable you to animate changes to CSS properties. Thus, you can increase the width of an element gradually instead of immediately. This can create some nice effects in your web page.
  • CSS 2D Transformations October 10, 2014
    This latest CSS tutorial explains how to perform 2D transformations on HTML elements with CSS 3.0.
  • Java's AtomicInteger October 8, 2014
    Java's AtomicInteger provides atomic (thread safe) operations on an int variable. For instance, get(), set() and compareAndSet(). This is useful if you have multiple threads with access to the same int value.

RSS Code Explosion Blog

  • Coding Culture: Are Female Coders Different Behaviorally From Male Ones? August 11, 2013
    I recently skimmed an article that elicited a thought in my head: do any behavior distinctions exist between male and female coders?  From my experience, coders tend to have certain distinguishing characteristics such as introversion and punctiliousness – yet I am unsure as to whether male and female coders have distinguishing characteristics.  I have into [ […]
    Collin Rusk
  • Test Driven Development: My First Attempt August 3, 2013
    Test Driven Development (TDD) receives its share of buzz; the methodology has become ubiquitous in discussions of software development – so I decided to enter the fray and to share some thoughts on my first pass at the process. To begin the software development process, I construct a cohesive vision of the product.  After this […]
    Collin Rusk
  • .Net Multi-Threading: Utilizing Wait Handlers July 7, 2013
    In multi-threaded applications, an operation must occasionally wait for an event to complete on another thread – a challenge that has many solutions but one that the proceeding sections will discuss – wait handlers. How Wait Handlers Solve the Problem They Provide a framework for carrying out the necessary actions: A wait handler can command […]
    Collin Rusk
  • Book Recommendation: Patterns of Enterprise Architecture by Martin Fowler May 26, 2013
    Patterns of Enterprise Application Architecture by Martin Fowler is a necessary read for any system architect.  The book provides excellent insight into approaching essential system-design decisions – although some of the content is outdated.  However, as I read Patterns of Enterprise Application Architecture, I found myself thinking of designs in a differen […]
    Collin Rusk
  • Comparing .Net IOC Frameworks April 19, 2013
    The subsequent article evaluates various IOC frameworks across a variety of areas.  The chosen frameworks, the criteria, their evaluation across the selected criteria, and the overall conclusion are described in the proceeding sections. The Chosen Frameworks Castle Project StructureMap Ninject Unity Autofac The Criteria Maturity: Maturity measures the extent […]
    Collin Rusk

my tweets

Follow

Get every new post delivered to your Inbox.

Join 346 other followers