Facebook Integration in Android Application - android

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.

Related

Few questions about key hash for Facebook SDK

I am developing an iOS app in swift and I am new to iOS but I have good knowledge of android. In Android we generally use:
public static void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "printHashKey()", e);
} catch (Exception e) {
Log.e(TAG, "printHashKey()", e);
}
}
to generate a key hash but now I need key hash to register my iOS project on facebook development console. I have no idea how to do it. So I want understand:
What is the role of key-hash. Is it like: In development mode if we make a build from our IDE and the machine key-hash is register on facebook then we can use facebook login else not. But from android code to generate key-hash it seems like package dependent(Uff!! lots of confusion).
How to generate key hash for an iOS app?
Can we use same key has for both iOS and android application?
Please share your thoughts and solution.

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());
}

error while adding development keyhash in developer.facebook.com

i am currently making a demo app for integrating Facebook sso and i made a debug keyhash for login via facebook but when i am adding development keyhash in facebook developers site its asking me for the release keyhash at the same time and i dont want to upload this demo to the playstore and its not allowing me to finish the process.
Please anyone suggest me something so that i can proceed.
public void generateHashKeyForFacebook(Context context) throws Exception {
try {
PackageInfo info = context.getPackageManager().getPackageInfo("com.yourPackageName", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("FBKeyHash >>> ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
Just put this function to your activity and see your log cat for obtaining your hash key
Below is the link
https://developers.facebook.com/docs/android/getting-started

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());
}

Generating hash key for facebook development

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...

Categories

Resources