带有无效密钥哈希的 Android Facebook 集成 [英] Android Facebook integration with invalid key hash

查看:25
本文介绍了带有无效密钥哈希的 Android Facebook 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个应用程序中,我需要从 Facebook 获取数据...我正在这样做:

我已经创建了应用 ID.它登录成功,但注销后,我登录,然后它给了我:

我做错了什么?我正在使用 Facebook SDK... 我已经在我的手机上安装了 Facebook... 它在模拟器中运行良好,但没有内置 Facebook 应用程序已安装.

这是我的代码:

if (FB_APP_ID == null) {Builder alertBuilder = new Builder(this);alertBuilder.setTitle("警告");alertBuilder.setMessage("Facebook 应用程序 ID 必须是" +在运行此示例之前指定:请参阅 App.java");alertBuilder.create().show();}//初始化调度器Dispatcher dispatcher = new Dispatcher(this);dispatcher.addHandler("登录", LoginHandler.class);dispatcher.addHandler("stream", StreamHandler.class);dispatcher.addHandler("注销", LogoutHandler.class);//如果会话已经存在,则渲染流页面//立即地.否则,呈现登录页面.会话会话 = Session.restore(this);如果(会话!= null){dispatcher.runHandler("stream");}别的 {dispatcher.runHandler("登录");}

解决方案

生成的哈希键错误.您可以通过两个步骤获取哈希键.

一种是通过命令提示符.另一种是通过编码.通过命令提示符的哈希键仅在第一次使用.我不知道原因.我也遇到了同样的问题.所以我以编程方式尝试了它.

请按照以下步骤操作:

oncreate()中粘贴以下代码.

尝试{包信息信息 = getPackageManager().getPackageInfo("com.example.packagename",PackageManager.GET_SIGNATURES);for(签名签名:info.signatures){MessageDigest md = MessageDigest.getInstance("SHA");md.update(signature.toByteArray());Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));}}抓住(NameNotFoundException e){}捕获(NoSuchAlgorithmException e){}

在上面的代码中用你的包名修改com.example.packagename",没有失败(你可以在Android清单文件中找到你的包名).

运行您的应用程序.转到粘贴上述代码的活动.在 LogCat 文件中,搜索KeyHash".您可能会找到一个密钥散列.复制密钥哈希并转到 Facebook 应用程序仪表板页面.转到设置并输入如下图所示的详细信息.

完成上述步骤后,再次重新启动应用程序.您现在可以登录 Facebook.有关密钥哈希的更多详细信息,请查看链接.

如果您在设置页面中添加了错误的信息,则意味着会出现一些错误.所以在那里使用正确的信息.此外,如果公众(除您之外)需要使用您的应用程序意味着您需要启用权限(在设置旁边的状态和审核"中更改是").>

In one of my apps I need to get data from Facebook... I am doing this:

I have created app ID. It logs in successfully, but after logging out, I log in, and then it gives me:

What is wrong I am doing? I am using the Facebook SDK... I have installed Facebook on my phone... It is running well within an emulator, but that does not have the inbuilt Facebook application installed.

This is my code:

if (FB_APP_ID == null) {
    Builder alertBuilder = new Builder(this);
    alertBuilder.setTitle("Warning");
    alertBuilder.setMessage("A Facebook Applicaton ID must be " +
                            "specified before running this example: see App.java");
    alertBuilder.create().show();
}

// Initialize the dispatcher
Dispatcher dispatcher = new Dispatcher(this);
dispatcher.addHandler("login", LoginHandler.class);
dispatcher.addHandler("stream", StreamHandler.class);
dispatcher.addHandler("logout", LogoutHandler.class);

// If a session already exists, render the stream page
// immediately. Otherwise, render the login page.
Session session = Session.restore(this);
if (session != null) {
    dispatcher.runHandler("stream");
}
else {
    dispatcher.runHandler("login");
}

解决方案

The generated hash key is wrong. You may get the hash key using two steps.

One is through a command prompt. Another one is through coding. The hash key through a command prompt is working on the first time only. I don't know the reason. I have also got the same problem. So I tried it through programmatically.

Follow these steps:

Paste the following code in oncreate().

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

Modify "com.example.packagename" with your package name in the above coding without fail (you may find your package name in the Android manifest file).

Run your application. Go to the activity where you pasted the above code. In the LogCat file, search for "KeyHash". You may find a key hash. Copy the key hash and go to Facebook application dashboard page. Go to settings and enter the details like in the below image.

Once you finished the above step, relaunch the app again. You may now log into Facebook. For more details about key hash, check the link.

If you add wrong information in the settings page, it means it will give some error. So use the correct information there. And also if the public (other than you) need to use your application means you need to enable the permission (change "yes" in the "Status & Review" next to the setting).

这篇关于带有无效密钥哈希的 Android Facebook 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆