Key hash for Android-Facebook app

后端 未结 30 3136
误落风尘
误落风尘 2020-11-22 01:17

I\'m working on an Android app, in which I want to integrate a Facebook posting feature. I downloaded the Facebook-Android SDK, and I got the readme.md (text file) in there,

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 01:50

    The best approach is to use the following code:

    private void getHashKey(String pkgName)
    {
        try
        {
            PackageInfo info = getPackageManager().getPackageInfo(pkgName, PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures)
            {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String hashKey = Base64.encodeBytes(md.digest());
                _hashKey_et.setText(hashKey);
                Log.i("KeyTool", pkgName + " -> hashKey = " + hashKey);
            }
        }
        catch (NameNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (NoSuchAlgorithmException e)
        {
            e.printStackTrace();
        }
    }
    

    But I was so frustrating with the fact that there is no simple tool to generate the HashKey for the Facebook app. Each time I had to play with Openssl and Keytool or to use a code to get the hash from signature ...

    So I wrote a simple KeyGenTool that will do that work for you: -> KeyGenTool on Google Play <-

    Enjoy :)

提交回复
热议问题