Generating hash key for facebook development - android

I have recently started working on facebook API, where I came under the situation of generating Hash key and registering it on facebook for further use.
For that, I used the following code
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
All worked well, as I was able to work with facebook in my app.
But, after publishing the app on playstore, I found the error Invalid_Android_key parameter. The key does not match any allowed key Configure your app key hashes at https://developers.facebook.com/apps/..........
Please, let me know the cause of this problem and how to handle this.

I had same Problem, after creating the apk, the key hash is changed! because using this code u get the debug keystore hash, but when creating apk, it's another hash, gotta capture it from log after trying ur apk on emulator , then delete code and export again without this log , i know it's a hassle but for me it was easier than keytool...

Related

invalid key hash - android facebook

I've created an app which uses the facebook login. I've added the key hash to the facebook developer page and it worked fine in all devices.
Now I've uploaded the app to google play, and when I try to login, it sais that the key hash does not match any stored key hashes.
I copied the key hash in the error message and pasted it. Still - doesn't work.
I tried to generate a key hash in cmd using the release key store - no luck.
Does anyone know what is the problem and how to fix it?
Thanks in advance!
Try adding the following code snippet to your app while it's signed with the release certificate, compare the hash output with the one you submitted to the Facebook portal:
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.package.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hash= new String(Base64.encode(md.digest(), 0));
Log.e("hash", hash);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}

Facebook API Exception

i just implemented Facebook log in into my android application. when i try to log in with Facebook i got following exception in log-cat.
Error Log :
com.facebook.http.protocol.ApiException: Key hash oZgj_um2MGi1eYpfTqwytjLMN10 does not match any stored key hashes
I already added this key hash into my developer account app page.But still i am facing same issue.
Your HashKey is wrong. It should have 28 characters while your hash key 27 characters the hashkey always ends with =. So I think you have missed it. Please check it again and
Change your hashkey by generating it programatically from the following code given in Facebook Docs and defined at Facebook Integration in Android Application
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.example.yourpackagename", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}

Hash key for android facebook app

I'm trying to generate Key hash to incorporate Facebook Application in my Apps.
The problem is that;
I'm actually getting the right key hash, but i'm still getting the wrong app key hash.
(Maybe I'm not taking the right part from the whole key..)
Any help will be very appreciated, I'm pretty lost here...
Problem Fixed! :
Just needed to get rid of the "=" sign after copying the key from the CMD.
Please let us know how you are getting your Key-Hash. If from keytool, then let us know the procedure, may be we will be able to fix, what are your missing.
In the meantime you can use the following code to get the Key-Hash.
private void getAppKeyHash() {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
Log.d("Hash key", something);
}
}
catch (NameNotFoundException e1) {
// TODO Auto-generated catch block
Log.e("name not found", e1.toString());
}
catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
Log.e("no such an algorithm", e.toString());
}
catch (Exception e){
Log.e("exception", e.toString());
}
}
Now from the logcat you can find the Key-Hash. For more info Please check it form facebook-sdk
Problem Fixed! :
Just needed to get rid of the "=" sign after copying the key from the CMD.

Facebook Integration in Android Application

I had integrated facebook in my android application .
Generate key using debugkeytool and it works fine on both emulator and real device.
Now i have to make release apk file and i had created keystore using eclipse android tool
to export signed application package .
And using this keystore i had generated new key hash for facebook and set it on facebook developers site.
but still i am not able to post on facebook wall after signing my app with my own created keystore.
I had check all the steps for creating keystore and it is correct.
please help me out of this situation.
Thanks
I got the same error but when i checked the hash key by PackageManager i got the different hash key of the application and update it on facebook and it worked for me.
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.example.yourpackagename", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
change your package name in the code. The hash key will be printed in the log.
It may help you.

Android FacebookSDK gives me "is misconfigured for Facebook login"

I have searched for info on the "is misconfigured for Facebook login" error message but have found no working solution. I have set Util.ENABLE_LOG to true but I get no error message in my log at all and so I can not figure out what is causing this.
I am developing with Eclipse on a Mac.
I have generated a hash with the keygen tool.
It seems Eclipse is looking for the debug.keystore in the correct location.
I simply call facebookSDK.authorize(activity, this); where activity is my main activity holding a SurfaceView that draws my UI on canvas (its a game like app), and this opens the FacebookSDK login UI just fine and I can log in but it then gives me this "misconfigured" error message (but nothing in the logs).
The callback methods "onComplete, onFacebookError, onError, onCancel" never gets called.
So, Im stuck here! Any ideas to what I can do to figure out what the problem really is?
Thank you
Søren
Ah now I know what the problem was! When you generate the hash you must use "android" as the password, I did not catch that one.
Also make sure to use this code to get correct hash, instead of command, since it gives different hashes for pc, mac and linux:
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.myname.lolo", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
//String something = new String(Base64.encode(md.digest(), 0));
* String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
}
catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
}
catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
}
catch (Exception e){
Log.e("exception", e.toString());
}
And u can delete this code afterwards

Categories

Resources