I\'m working on an Android app, in which I want to integrate a Facebook posting feature. I downloaded the Facebook-Android SDK, and I got the readme.md (text file) in there,
For Linux
Open Terminal :
For Debug Build
keytool -exportcert -alias androiddebugkey -keystore debug.keystore | openssl sha1 -binary | openssl base64
you wil find debug.keystore from ".android" folder copy it from and paste on desktop and run above command
For release Build
keytool -exportcert -alias <aliasName> -keystore <keystoreFilePath> | openssl sha1 -binary | openssl base64
NOTE : Make sure In Both case it must ask for password. If it does not asks for password that means something is wrong in command.
Here are the steps-
Download openssl from Google code (If you have a 64 bit machine you must download openssl-0.9.8e X64 not the latest version)
Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.
detect debug.keystore file path. If u didn't find, then do a search in C:/ and use the Path in the command in next step.
detect your keytool.exe path and go to that dir/ in command prompt and run this command in 1 line-
$ keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
For more info visit here
Solved mine too in Android Studio but with slight different approach.
To get the SHA-1 value in Android Studio.
SHA-1 value look like this CD:A1:EA:A3:5C:5C:68:FB:FA:0A:6B:E5:5A:72:64:DD:26:8D:44:84
and open http://tomeko.net/online_tools/hex_to_base64.php to convert your SHA1 value to base64. This is what Facebook requires get the generated hash " ********************= " and copy the key hash to the facebook app console.
Part of this answer taken from here Github Link
This is what is given at the official page of Facebook:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Let me break this command into fragments.
Look for "keytool.exe"
. You can search that on the C: drive. You can find it in "java jdk"
or "java jre"
. If you have installed multiple versions, choose any.
Open a CMD prompt and go to the above directory where you found "keytool.exe"
.
Clip the "exe`" and paste the above command provided on the Facebook page.
You will get an error on entering this that OpenSSL is not recognized as in input output command.
Solution : Download "Openssl" from OpenSSL (if you have a 64-bit machine you must download openssl-0.9.8e X64). Extract and save it anywhere... I saved it on the C: drive in the OpenSSl
folder
Replace the openssl in the above command in which you was getting an error of OpenSSL with "C:\OpenSSL\bin\openssl" at both the places after the pipe, "|".
If prompted for a password, enter android
.
And you will get your hash key. For further steps, refer again to the Facebook page.
You can get key hash from SHA-1 key. Its very simple you need to get your SHA-1(Signed APK) key from Play Store check below image.
Now Copy that SHA-1 key and past it in this website http://tomeko.net also check below image to get your Key Hash.
try this :
1) get hash key from using command line (Official Doc : https://developers.facebook.com/docs/android/getting-started)
keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl
base64
OR
2) get hash key using code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Hask Kay generation
GetKeyHase();
}
private void GetKeyHase() {
try {
PackageInfo info = getPackageManager().getPackageInfo("ADD YOUR PACKAGE NAME", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = (MessageDigest.getInstance("SHA"));
md.update(signature.toByteArray());
String hashkey_value = new String(Base64.encode(md.digest(), 0));
Log.e("hash key", hashkey_value);
//check you logcat hash key value
}
}catch (Exception e) {
Log.e("exception", e.toString());
}
}