Search code examples
androidfacebookhashfacebook-android-sdk

Invalid hash key error while integrating facebook login with android


I was displayed with a message saying " invalid hash key . the hash key ********** is not ... " . But I copied this key into the MyApp/Settings/keyhash . Yet is doesn't work .

I tried generating the hash key with the command keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64.

This generated another hash key ,even after i updated My app with the new key . The app still does not work .

I had this app initially in an other computer ,it work fine there . Only after shifting the project to a new computer all these issues have come .

these are my logcat values :

07-28 13:06:40.446  15812-15812/com.zobbr.mettl.zobbr I/System.out﹕ waiting for debugger to settle...
07-28 13:06:40.646  15812-15812/com.zobbr.mettl.zobbr I/System.out﹕ waiting for debugger to settle...
07-28 13:06:40.847  15812-15812/com.zobbr.mettl.zobbr I/System.out﹕ waiting for debugger to settle...
07-28 13:06:41.047  15812-15812/com.zobbr.mettl.zobbr I/System.out﹕ waiting for debugger to settle...
07-28 13:06:41.249  15812-15812/com.zobbr.mettl.zobbr I/System.out﹕ waiting for debugger to settle...
07-28 13:06:41.450  15812-15812/com.zobbr.mettl.zobbr I/System.out﹕ debugger has settled (1359)
07-28 13:06:41.627  15812-15812/com.zobbr.mettl.zobbr D/Your Tag﹕ bPx5YeVB5lOVc+oiEwo/VWuV8+k=
07-28 13:06:41.641  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: switch
07-28 13:06:41.641  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: foreignObject
07-28 13:06:41.641  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: pgfRef
07-28 13:06:41.648  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: pgf
07-28 13:06:41.664  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: switch
07-28 13:06:41.664  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: foreignObject
07-28 13:06:41.664  15812-15812/com.zobbr.mettl.zobbr D/SVGAndroid﹕ UNRECOGNIZED SVG COMMAND: pgfRef

Solution

  • Use this code to generate hash key

    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("Your Tag", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
        } catch (NameNotFoundException e) {
    
        } catch (NoSuchAlgorithmException e) {
    
        }