Key hash for Android-Facebook app

后端 未结 30 2737
误落风尘
误落风尘 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条回答
  •  梦毁少年i
    2020-11-22 01:55

    Add this code to onCreate of your activity, it will print the hash under the KeyHash tag in your logCat

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                               getPackageName(),
                               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) {
    
    }
    catch (NoSuchAlgorithmException e) {
    
    }
    

    You can add multiple hashkeys for your account, so if you been running in debug don't forget to run this again in release mode.

提交回复
热议问题