How to create a Facebook key hash?

前端 未结 9 1125
独厮守ぢ
独厮守ぢ 2020-12-14 13:15

In the Facebook android tutorial we are told to use following code to create a key hash:

keytool -exportcert -alias androiddebugkey -keystore ~/.andro

相关标签:
9条回答
  • 2020-12-14 13:54

    One brute force option is to just go ahead and try to share something from your app. My app then displays a Facebook page with the key it is trying to match. Then you can just copy this key and put it in your Facebook 'Settings' page on your developer Facebook account.

    Not ideal, but in a pinch it may be helpful.

    0 讨论(0)
  • 2020-12-14 13:54

    There are two ways to generate Hashkey for Facebook.

    1. You can use the following code snippet

       try {
           PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
           for (Signature signature : info.signatures) {
               MessageDigest messageDigest= MessageDigest.getInstance("SHA");
               messageDigest.update(signature.toByteArray());
               String hashKey = new String(Base64.encode(messageDigest.digest(), 0));
               Log.i("Hash Key ", "value is " + hashKey);
           }
       } catch (NoSuchAlgorithmException e) {
           Log.e("Exception ", "is ", e);
       } catch (Exception e) {
           Log.e("Exception ", "is ", e);
       }
      
    2. You can create Hashkey for Facebook Online by pasting your SHA1 on This link

    Happy Coding :)

    0 讨论(0)
  • 2020-12-14 14:04
     /**
         * Generates the hash key used for Facebook console to register app. It can also be used for other sdks) Method copied from: https://developers.facebook.com/docs/android/getting-started/
         */
        public static String printHashKey(Context ctx) {
            // Add code to print out the key hash
            try {
                PackageInfo info = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    return Base64.encodeToString(md.digest(), Base64.DEFAULT);
                }
            } catch (NameNotFoundException e) {
                return "SHA-1 generation: the key count not be generated: NameNotFoundException thrown";
            } catch (NoSuchAlgorithmException e) {
                return "SHA-1 generation: the key count not be generated: NoSuchAlgorithmException thrown";
            }
    
            return "SHA-1 generation: epic failed";
        }
    
    0 讨论(0)
提交回复
热议问题