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

当前回答

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

对于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

释放键哈希源代码

其他回答

我也有同样的问题。我确信这是由于非常小的错误,是的,它是!

我找到了解决方案:

当在我的计算机中生成调试哈希键时,我输入了我的系统密码。但密码应该是-

输入keystore密码:“android”。 这是我唯一的问题。

-----用于生成调试键哈希,使用此命令-

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

输入密钥库密码:'android'

-----要生成释放密钥哈希,使用命令-

keytool -exportcert -alias "alias of keystore" -keystore "Your path to the keystore when signing app" | openssl sha1 -binary | openssl base64

执行此命令后,提供您的密钥存储库密码。

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

尽管这个问题已经回答了很多有用的方法,我只是想补充说,当我遵循Rafal Maleks的答案(使用谷歌Play Console上的散列键),我无法使用应用程序签名SHA1密钥,仍然从Facebook得到了一般错误。相反,我需要使用来自上传证书部分的SHA-1证书指纹(就在谷歌Play Console的应用程序签名部分的下面)。否则,同样的过程;

从谷歌播放控制台的“上传证书”中拷贝SHA-1证书指纹 使用:http://tomeko.net/online_tools/hex_to_base64.php转换SHA-1并复制输出(base64) 将其粘贴到developer.facebook.com上的Key Hashes输入中并保存更改。

希望这个答案不是多余的,并将帮助那些不能让它与应用程序签名证书一起工作的人。

现在Facebook登录工作在我的应用程序在调试和发布模式。

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

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

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

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

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

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

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

Facebook使用的不是用于调试的默认密码和别名。你需要改变它,它会工作。

/usr/lib/jvm/jdk1.8.0_66/bin/keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

如果你没有修改任何默认密码,它应该是“android”。

您还可以在构建中配置它。gradle文件。但是生成散列时应该使用相同的别名密码:

android {
    signingConfigs {
        release {
            storeFile file("~/.android/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }
}