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
At last :)
Here my story :
Add this code to your main activity, after you set layout.
try {
PackageInfo info = getPackageManager().getPackageInfo("PROJECTNAME", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.e("MY KEY HASH:", sign);
//textInstructionsOrLink = (TextView)findViewById(R.id.textstring);
//textInstructionsOrLink.setText(sign);
Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show();
}
} catch (NameNotFoundException e) {
Log.d("nope","nope");
} catch (NoSuchAlgorithmException e) {
}
Change PROJECTNAME to your package name!
Even though this thread is old, yet I would like to share my experience (recently started working with facebook), which seems to me straight:
To get the Development key for facebook integration, use the following command from the command line in windows:
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%.android\debug.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
NOTE!: please replace the path for openssl.exe (in this example it is "C:\openssl\bin\openssl.exe") with your own installation path.
Enter keystore password: android
Type android as password as shown above.
Thats it! You will be given a 28 character long key. Cheers!
Use the same procedure to get the Release key. Just replace the command with the following and use your release key alias.
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH | "PATH FOR openssl.exe" sha1 -binary | openssl base64
I. Create key hash debug for facebook
Add code to print out the key hash for facebook
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.google.shoppingvn", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("KeyHash:",
Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
II. Create key hash release for facebook
Download openssl-0.9.8e_X64
Make a openssl folder in C drive
Extract Zip files into openssl folder
Start -> Run: cmd (press enter)
(press) cd C:\Program Files\Java\jdk1.6.0_45\bin. Note: C:\Program Files\Java\jdk1.6.0_45\bin: is path to jdk folder in your computer
(press) keytool -exportcert -alias gci -keystore D:\folder\keystorerelease | C:\openssl\bin\openssl sha1 -binary | C:\openssl\bin\openssl base64. Note: D:\folder\keystorerelease: is path to your keystorerelease
Enter keystore password: This is password when your register keystorerelease.
Then you will have a key hash: jDehABCDIQEDWAYz5Ow4sjsxLSw=
Login facebook. Access to Manage Apps. Paste key hash to your app on developers.facebook.com
If your password=android is wrong then Put your pc password on that it works for me.
And for generate keyHash try this link Here
The only thing working for me is using the password android
. Why is that not mentioned in any guides out there?
Simplest way to generate hash key.
Requirement: SHA1 Key
You can get SHA1 Key from your keystore file by two ways
1) Locate your keystore file, open command prompt on that location then use below mentioned command
keytool -list -v -keystore {keystore_name} -alias {alias_name}
and then enter your password then it will return md5, sha1 and sha256 key.
OR
2) By running signingReport
Refer below image.
after you run the file your output will be generated containing required sha1 key.
After you get the required SHA1 Key
Then goto
http://tomeko.net/online_tools/hex_to_base64.php
and paste your sha1 key
and finally you will get Required HashKey which you can use it to apply on facebook.