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

当前回答

我也有同样的问题。首先登录,没问题,但接下来,一个无效的键散列。

Unity的Facebook SDK得到了错误的键散列。它从"C:\Users\ your user".android\debug获取键。密钥存储库”,在理想情况下,它应该从您在项目中创建的密钥存储库中获取。这就是为什么它告诉你键哈希没有注册。

正如Madi所建议的,您可以按照此链接上的步骤找到正确的键。只需确保将它们指向项目中的密钥库。否则你就拿不到正确的钥匙。

其他回答

我看到很多人给出了困难的答案,通过我解决我的问题的答案只是去项目/android文件夹/应用程序使用终端,这是你调试的地方。Keystore文件为

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

复制粘贴这个命令,替换你的项目/android/app/build.gradle中的别名和密码

debug {
  storeFile file('debug.keystore')  
  storePassword 'android'
  keyAlias 'androiddebugkey'      <---- alias
  keyPassword 'android'           <---- password
}

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

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

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

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

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

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

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

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

下面的代码将为您提供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.

如果您正在使用谷歌Play App签名:

在谷歌播放控制台打开App签名部分,获取App签名证书下的SHA-1哈希值。然后将其转换为Base64,例如使用以下工具:十六进制-> Base64字符串解码器