Android Facebook SDK: Key hash does not match any stored key hashes when uploading google play

前端 未结 8 2078
南旧
南旧 2020-12-12 22:44

My app uses facebook api for user login. On developing it works fine, but when I uploaded it to google play it stops working.

This is the error log:

         


        
8条回答
  •  情书的邮戳
    2020-12-12 23:43

    This was giving the wrong key for me.

    keytool -exportcert -alias  -keystore  | openssl sha1 -binary | openssl base64
    

    A workaround that worked for me was: 1. Put this code in your launching activity

    private void printKeyHash(){
        // Add code to print out the key hash
        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("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
        } catch (NameNotFoundException e) {
            Log.d("KeyHash:", e.toString());
        } catch (NoSuchAlgorithmException e) {
            Log.d("KeyHash:", e.toString());
        }
    }
    
    1. Export the app for publishing on play store using the .keyStore
    2. Install the app before uploading to play store and run it and note the keyHash printed.
    3. Add the keyHash to the Facebook App.

    Hope this helps someone.

提交回复
热议问题