Invalid Key hash with Facebook Android SDK - android

I'm trying to use Facebook Android SDK to develop a simple app with the Facebook Login Button.
But i'm having trouble with Key Hashes. I've created both a debug key and a release key:
Debug key:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
Release key:
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
And then i copied this key hashes in the Facebook Developers page.
When i export the apk and copy it into the device it works well, but when i try to install the app from Eclipse (run as/debug as Android Application) it doesn't work. It seems that the app is using a different key hash from the one i've created with keytool.
Anyone knows how to solve this problem?

Try to get the HashKey from here
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.tryitonjewelry", PackageManager.GET_SIGNATURES); //Your package name here
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) {
}
}

try {
PackageInfo info = getPackageManager().getPackageInfo("your pakage name here", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("KeyHash:", "key is: "+Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
Log.e("error","error name not found");
} catch (NoSuchAlgorithmException e) {
Log.e("error","error no algorithm");
}**strong text**
By using this one u can get ur key hash and then use this one in facebook devloper site.

try {
PackageInfo info = getPackageManager().getPackageInfo("your package name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", "KeyHash: " + Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
}
catch (PackageManager.NameNotFoundException e) {
}
catch (NoSuchAlgorithmException e) {
}

Related

Generating release key hash in Linux OS(Ubuntu) : Android Facebook SDK

How can I generate the right release key hash in Ubuntu?
I have already referred this but i can't get my answer.
After trying many time i got solution for fragment which give me a release key hash.
try {
PackageInfo info = getActivity().getPackageManager().getPackageInfo(
"com.yourappname.app",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash", "KeyHash:" + Base64.encodeToString(md.digest(),
Base64.DEFAULT));
Toast.makeText(getActivity().getApplicationContext(), Base64.encodeToString(md.digest(),
Base64.DEFAULT), Toast.LENGTH_LONG).show();
}
} catch (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
And i got this command from here for terminal which give me release key hash.
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

Invalid Key hash facebook android sdk

I'm trying to use Facebook Android SDK to develop a simple app with the Facebook Login Button. But i'm having trouble with Key Hashes. I've created both a debug key and a release key:(in mac)
Debug key:
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
i also tryed this code also
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.me", PackageManager.GET_SIGNATURES); //Your package name here
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) {
}
}
And then i copied this key hashes in the Facebook Developers page.when i run my app with eclipse then working.but When i export the apk and copy it into the device it does not working.
also i have another problem.if my divice has installed Facebook Application then also not working.
how i can solve my problem?
When you get Invalid key hash, it also shows the correct key hash and says "The keyhash XXXXX didnot match with any of the stored keyhashes" . so copy that displayed keyhash and append "=" at the end as XXXXX= and add it in the key hash section. Hope it works....
this might also work
public static void showHashKey(Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
"com.example.me", PackageManager.GET_SIGNATURES); //Your package name here
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) {
}
}

How to assign "Development Key Hash" for a device and not an emulator

login with Facebook
how can I assign a "Development Key Hash" to a android device?
using KeyTools
keytool -importkeystore -srckeystore path/to/keystore/with/forgotten/pw -destkeystore path/to/my/new/keystore
I sign only the application using the emulator and not device
how can I fix it?
You can get the key hash for that device with this snippet, just add the code in your MainActivity and check the Logcat.
try {
PackageInfo info = getPackageManager().getPackageInfo(
"com.facebook.samples.hellofacebook",
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) {
}
BR

Generate hash key for android mobile app

I am working on a android app and has to provide the hashkey to facebook. I have tried 3 appoarch but none of them works.
By following the official doc:
1.) I write a command in windows like this
"C:\Program Files\Java\jdk1.7.0_17\bin\keytool.exe" -exportcert -alias androiddebugkey -keystore C:\hk7.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
output:
57GY9jCxTL9lwhI9oAsjNZN1UJ4=
2.) And the programatically way
try {
PackageInfo info = getPackageManager().getPackageInfo("com.package.mypackage", 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);
Toast.makeText(getApplicationContext(),sign, Toast.LENGTH_LONG).show();
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
output:
PH//aR6qmcnZxj/n+4oT6AzEMZQ=
Works but only for my device
3.) the alias value
keytool -alias hk7 -exportcert -keystore C:\hk7.keystore | "C:\openssl\bin\openssl.exe" sha1 -binary | "C:\openssl\bin\openssl.exe" base64
output:
kiHnmqD3oxggF1Y7rgTqaWTPZk4=
Only the second way works but it is only for my device . In my app , I log the exception , it said the API key does not match . but it seems each device has its own key. How to fix that? and is it caused my openssl is too old? or the android side implementation problem? Are there any site for testing whether the key is work? Thanks for helping
2nd way is t best one, Now you need to add every device hashkey on which you want to test as your app is not on playstore .. once you upload t app on playstore/sign with a perticular keystore then you have to add only that keyhash.... Use this function to get KEYHASH
private void printKeyHashForThisDevice() {
try {
PackageInfo info = getPackageManager().getPackageInfo("com.package", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Logger.logger("============================================");
Logger.logger("KeyHash================ ", keyHash);
Logger.logger("============================================");
System.out.println("KeyHash================ " + keyHash);
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}

Error: Invalide android:_key parameter. The key does not match allowed key

Hy! I tried to integrate the facebook sdk with my android app. I obtain my key kashes using this comand:
keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64
After that I, i create a new facebook application, where i selected native android app and i give my hashkey.
But when I run the app, I receive this error:
Can someone to help me?
Try this when session open
try {
PackageInfo info = getPackageManager().getPackageInfo("YOUR_PACKAGE_NAME", 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) {
}

Categories

Resources