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

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

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

这是我的代码:

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");
}

当前回答

这里有很多正确答案。只有一件事:

将收到的散列粘贴到应用程序→设置→主,而不是通过快速入门教程。

其他回答

我通过更改调试的phat解决了这个问题。正确的phat必须是你的Android项目文件的phat。是这样的:

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\yourUser\Documents\other\yourProjectName\android\app\debug.keystore" | "C:\openssl\openssl-3\x64\bin\openssl" sha1 -binary | "C:\openssl\openssl-3\x64\bin\openssl" base64

如果你不知道如何获得openSSL,我向你推荐youtube上的这个视频:https://youtu.be/aZlkW3Evlx4

如果你遇到了这个问题,把这个键输入到你的developer.facebook.com:

然后确保你的应用在developer.facebook.com上是活跃的。

这个绿色圆圈表示应用程序是活的:

如果不是,那么按照以下两个步骤让你的应用上线:

步骤1进入应用程序→设置→添加“联系邮箱”,选择“保存更改”。

步骤2进入App Review选项,确保该选项为Yes。我加了一张截图:

注意:如果你想复制hashkey,请检查LogCat中的BlueServiceQueue。

经过长时间的研究,我们找到了解决办法。

我们将权限设置为:

loginButton.setReadPermissions(public_profile email);

这是第一次工作,但当我们重新登录Facebook时,它给出了无效的哈希错误。

简单的解决方案是将上面的行更改为:

loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));

它的工作就像一种幸福!

Facebook应该返回正确的异常,而不是误导性的无效哈希键错误。

我也有同样的问题。

确保使用生成hashkey(存储在Facebook开发者部分)的相同设备构建APK文件。

当我调试我的应用程序时,我也遇到了同样的问题。我重写了你在附件图像中划掉的散列(Facebook说无效的那个),并将它添加到Facebook的开发者控制台的键散列中。只是要注意错别字。

这个解决方案更像是一个简单的变通方案,而不是一个合适的解决方案。