Facebook集成身份验证错误: - 无效的密钥哈希。密钥哈希K / MLFPcpd4lHR56HLtn9eYQ3pjQ与任何存储的密钥哈希都不匹配

时间:2014-12-17 16:11:19

标签: android facebook-android-sdk

这是单击按钮时执行的代码。

public void handleSharing() { if (FacebookDialog.canPresentShareDialog(getApplicationContext(), FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) { // Publish the post using the Share Dialog FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(MainActivity.this) .setLink("https://developers.facebook.com/android") .setApplicationName("SharingApp") .build(); uiHelper.trackPendingDialogCall(shareDialog.present()); } else { // Fallback. For example, publish the post using the Feed Dialog publishFeedDialog(); }

1 个答案:

答案 0 :(得分:0)

调用此方法并获取Key哈希值,然后将此哈希键添加到通过developer.facebook.com注册的应用程序中: public static void showHashKey(Context context) {

try {
        PackageInfo info = context.getPackageManager().getPackageInfo(
                "com.example.sharingapplication", 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) {
    }
}