Key hash for Android-Facebook app

后端 未结 30 2692
误落风尘
误落风尘 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:46

    Kotlin code to get Hash key

     private fun logHashKey() {
        try {
            val info = getPackageManager().getPackageInfo("your.package.name", PackageManager.GET_SIGNING_CERTIFICATES);
            for (signature in info.signingInfo.signingCertificateHistory) {
    
                val md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                val something = Base64.getEncoder().encodeToString(md.digest());
                Log.e("hash key", something);
            }
        } catch (e1: PackageManager.NameNotFoundException) {
            Log.e("name not found", e1.toString());
        } catch (e: NoSuchAlgorithmException) {
            Log.e("no such an algorithm", e.toString());
        } catch (e: Exception) {
            Log.e("exception", e.toString());
        }
    }
    

    Please don't forgot to generate keys in Debug and Release environment as they change as per build setting.

提交回复
热议问题