在我的一个应用程序中,我需要从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");
}

当前回答

如果你手动输入键散列(例如从手机到Facebook仪表板),请确保区分小L和大写I。

其他回答

您必须创建两个键散列,一个用于调试,另一个用于发布。

对于Debug键哈希:

在OS X上运行:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

在Windows上运行:

keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl
base64

调试键哈希源代码

对于Release键哈希:

在OS X上,运行(将<>之间的值替换为您的值):

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

在Windows上,使用(将<>之间的值替换为您的值):

keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64

释放键哈希源代码

我通过更改调试的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

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

我们将权限设置为:

loginButton.setReadPermissions(public_profile email);

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

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

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

它的工作就像一种幸福!

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

下面的代码将为您提供Facebook的散列,但您必须遵循以下步骤才能获得发布候选散列。

Copy and paste this code in your main activity 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) { } Generate a signed APK file. Connect your phone to a laptop and make sure it stays connected. Install and run the APK file in your phone by manually moving the release APK to your phone. Now look at Android LogCat (use filter KeyHash:). You should see your release hash key for Facebook. Simply copy and paste it in your https://developers.facebook.com/apps. It's under settings. Now you can test the app it should work perfectly well.

如果你手动输入键散列(例如从手机到Facebook仪表板),请确保区分小L和大写I。