Facebook Android Generate Key Hash

后端 未结 21 2035
误落风尘
误落风尘 2020-11-22 04:11

Trying to create an android app with Facebook integration, I\'ve gotten to the part in the docs where you have to generate a key hash file, it specifies to run the following

21条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 04:52

    The right key can be obtained from the app itself by adding the following code to toast the proper key hash (in case of Facebook SDK 3.0 onwards, this works)

    try {
                PackageInfo info = getPackageManager().getPackageInfo("com.package.mypackage",         PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    String sign=Base64.encodeToString(md.digest(), Base64.DEFAULT);
                    Log.e("MY KEY HASH:", sign);
                    Toast.makeText(getApplicationContext(),sign,         Toast.LENGTH_LONG).show();
                }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    

    Replace com.package.mypackage with your package name

提交回复
热议问题