1

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?

Söraka
  • 53
  • 1
  • 5
  • your answer is here [https://stackoverflow.com/questions/45706693/how-to-solve-this-facebook-key-hash-error/45708369#45708369](https://stackoverflow.com/questions/45706693/how-to-solve-this-facebook-key-hash-error/45708369#45708369) – Shailesh Bandil Sep 07 '17 at 12:33

2 Answers2

1

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();
    }
}
Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40
  • Hello. I already got the key hash from Unity, under Facebook Settings at Debug Android Key Hash, though that key does not solve the problem and it's not the one from the error. As I mentioned above, if I insert the key from the error, it works, but isn't it unique for all devices? – Söraka Sep 07 '17 at 12:40
0

Follow this steps for solution.

  1. 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(); 
        } 
    }
    
  2. Sign your APK.(release APK)

  3. Install generated signed APK to your mobile
  4. Connect your phone with pc.
  5. Now open screen where you put above code.
  6. Here your can see new HashKey in logcat
  7. Paste this HashKey in Facebook developer site where you app created.
  8. Enjoy with your application.
mrogal.ski
  • 5,828
  • 1
  • 21
  • 30
  • Hello. I already got the key hash from Unity, under Facebook Settings at Debug Android Key Hash, though that key does not solve the problem and it's not the one from the error. As I mentioned above, if I insert the key from the error, it works, but isn't it unique for all devices? – Söraka Sep 07 '17 at 12:54
  • Key has same for all devices, you app is live on Google play store ? Is this problem with sign apk only ? If yes so you need to add another key hash in developer.facebook.com as mentioned in steps of my answer – Chandresh Tarasariya Sep 07 '17 at 20:16