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

前端 未结 8 1981
南旧
南旧 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:40

    You followed the steps that facebook provides for the creation of a login application?

    You need a 'Production keyhash' obtained starting your release keystore:

    From comand line:

    keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64
    

    And add this key on facebook app page options.

    More information: Facebook docs

    0 讨论(0)
  • 2020-12-12 23:43

    This was giving the wrong key for me.

    keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | 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.

    0 讨论(0)
提交回复
热议问题