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

当前回答

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "www.icognix.infomedia",
                           PackageManager.GET_SIGNATURES);
    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        Log.d("YourKeyHash: ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        Log.d("YourKeyHash: ", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    }
}
catch (PackageManager.NameNotFoundException e) {
}
catch (NoSuchAlgorithmException e) {
}

其他回答

我尝试了之前所有的答案,没有一个对我的客户有帮助!

然后我的客户想起来他的设备上安装了Facebook应用程序。在他把它取下来之后。登录工作正常。

hashkey已经被更改,我已经用错误中的key替换了Facebook开发者控制台中的旧hashkey(如上所述),并且它可以工作!

Facebook应用程序本身可能就是问题所在,所以你最好在安装了Facebook应用程序的设备和未安装Facebook应用程序的设备上解决这一问题,并处理这两种情况。

这可能对有同样问题的人有所帮助。

使用下面的代码生成密钥散列 Keytool -exportcert -alias <your_keystore> alias -keystore <your_keystore_file> | openssl sha1 -binary | openssl base64 如何使用keytool 将其粘贴在Facebook开发人员的必填项域中 在Android Studio中,菜单文件→项目结构 添加签名参数。 选择口味 选择我们创建的签名配置。 选择构建类型 选择构建变体并构建它

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

将以下代码粘贴到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) {
    e.printStackTrace();
}
catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
}

只需修改包名。然后转到LogCat文件,在这里选择Debug搜索。然后你会找到哈希键。现在复制这个散列键,然后转到developer。facebook。app_id site,编辑你的散列键,然后按保存。现在再次运行Android项目。我认为问题会得到解决。

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