Invalid Key hash with Facebook Android SDK

后端 未结 3 658
情歌与酒
情歌与酒 2021-02-06 18:21

I\'m trying to use Facebook Android SDK to develop a simple app with the Facebook Login Button. But i\'m having trouble with Key Hashes. I\'ve created both a debug key and a rel

相关标签:
3条回答
  • 2021-02-06 18:56
     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:", "KeyHash:  " + Base64.encodeToString(md.digest(), Base64.DEFAULT));
             }
          }
          catch (PackageManager.NameNotFoundException e) {
    
          }
          catch (NoSuchAlgorithmException e) {
    
          }
    
    0 讨论(0)
  • 2021-02-06 18:57

    Try to get the HashKey from here

    public static void showHashKey(Context context) {
                try {
                    PackageInfo info = context.getPackageManager().getPackageInfo(
                            "com.example.tryitonjewelry", PackageManager.GET_SIGNATURES); //Your            package name here
                    for (Signature signature : info.signatures) {
                        MessageDigest md = MessageDigest.getInstance("SHA");
                        md.update(signature.toByteArray());
                        Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
                        }
                } catch (NameNotFoundException e) {
                } catch (NoSuchAlgorithmException e) {
                }
            }
    
    0 讨论(0)
  • 2021-02-06 19:01
     try {
                PackageInfo info = getPackageManager().getPackageInfo("your pakage name here", PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    Log.e("KeyHash:", "key is: "+Base64.encodeToString(md.digest(), Base64.DEFAULT));
    
                    }
            } catch (NameNotFoundException e) {
    
                Log.e("error","error name not found");
            } catch (NoSuchAlgorithmException e) {
    
                Log.e("error","error no algorithm");
    
            }**strong text**
    

    By using this one u can get ur key hash and then use this one in facebook devloper site.

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