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
Related
I am getting the "Invalid key hash" error on my Android even though my app is in production and the facebook app is set as public. If I put the key hash into the facebook settings it works fine, but I suppose this would only work on my own device. What am I getting wrong here?
You have to create a release apk and print keyhash using this method. and set that keyHash in fb consol.
public static void printHashKey(Context context)
{
// Add code to print out the key hash
try {
PackageInfo info = context.getPackageManager().getPackageInfo(
com.example.app.BuildConfig.APPLICATION_ID,
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 (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
Follow this steps for solution.
Paste this code in your activity.
public static void printHashKey(Context context)
{
// Add code to print out the key hash
try
{
PackageInfo info = context.getPackageManager().getPackageInfo( com.example.app.BuildConfig.APPLICATION_ID, 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 (PackageManager.NameNotFoundException e)
{
e.printStackTrace();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
}
Sign your APK.(release APK)
Install generated signed APK to your mobile
Connect your phone with pc.
Now open screen where you put above code.
Here your can see new HashKey in logcat
Paste this HashKey in Facebook developer site where you app created.
Enjoy with your application.
I m getting invalid key hash in the application I'm providing social media login functionality.
When I am logging first time using Facebook app installed on my device it works well but for second time it gives me invalid key hash error.
log that key hash and add that in facebook developer
private void onCreateHashKey() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
"your.package",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
I have tried hash key using .android debug key but still not getting my LinkedIn app connected with my App.
And also getting error like when i link with my Facebook App, LinkedIn also showing linked automatically.
Am i attach Facebook hash key in LinkedIn Account?
Please help me to get the correct hash key for eclipse specially.
public void generateHashkey(){
try {
PackageInfo info = getPackageManager().getPackageInfo(
PACKAGE,
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 (PackageManager.NameNotFoundException e) {
Log.d(TAG, e.getMessage(), e);
} catch (NoSuchAlgorithmException e) {
Log.d(TAG, e.getMessage(), e);
}
}
I have this problem, I create FB login with FB SDK Android with java in Eclipse. When i debug and run this app in Android Emulator all is correct, i can login i can logout. But when i export app to develop version (.apk), and install it at my phone or at genymotion emulator i geting this errors:
"Invlaid key hash. The key hash xxxxxxxxxxxxxxxxxxx does not match any stored key hashes. Configure your app key hashes at http://developers.facebook.com/apps/72012084472886"
The hash key is create correoct i use this:
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) {
}
Do you have some idea, what is wrong?
Thank you .
When you run an app via ADB Eclipse usually uses a keystore named debug.keystore, this keystore is usually the one you don't use on production apps. When you export your app and create a keystore, the keyhash will change value because you change keystore.
You can implement this code to your app so you can echo the keyhash to you stackrace:
public static void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageInfo(pContext, 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);
}
}
The snippet is only suitable for development, not for production!
I'm working on facebook android sdk. I'm getting the hash key using following code .Now I'm getting error Session state CLOSED_LOGIN_FAILED after login to Facebook.
Ref : if(session.isOpen()), facebook login on android always returning false
try {
PackageInfo info = getPackageManager().getPackageInfo(
"your.root.package",
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) {
}
OK MY SONS! LISTEN TO THIS SOLUTION AND BE SAVED
go to this solution and folow carefully:
http://www.helloandroid.com/tutorials/using-facebook-sdk-android-development-part-1
now pay close attention:
you must do it with java 1.6!!
in my case i did it twice like he suggested on my original keystore file as well-not sure if this
is essential.
last but not least:
go to the android developer site and press Status and Reviews
make your app public and open champein!
(i really hate face)