Trying to create an android app with Facebook integration, I\'ve gotten to the part in the docs where you have to generate a key hash file, it specifies to run the following
In my experience, openssl always being troublesome, I tried the second method suggested by facebook. And it's wonderful. This is the best method to get the hash key.
Second option is to print out the key hash sent to Facebook and use that value. Make the following changes to the onCreate() method in your main activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.loginhowto",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
...other operations
}//end of onCreate
Replace com.facebook.samples.loginhowto with your own package name ( package name in Manifest.xml).
Official link - https://developers.facebook.com/docs/android/login-with-facebook/ ( See the bottom of the page)
openssl folderopenssl folder in C:drivebin of openssl i.e C:\openssl\bin in command promptrun the following command to generate your keyhash. While generating hashkey it should ask you password.
keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Anhsirk.android\debug.keystore" | openssl sha1 -binary | openssl base64
NOTE: in the above code note that , you need to give your path to user ( i.e in my case it is C:\Users\Anhsirk , you just need to change this for your user account.
Give password as android
. If it don’t ask for password your keystore path is incorrect.
If everything works fine, it should give you the hashkey below.
