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

当前回答

我看到很多人给出了困难的答案,通过我解决我的问题的答案只是去项目/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
}

其他回答

我很遗憾地说,其实我什么都不管用。最后,帮助我的是从谷歌播放控制台获得上传SHA-1证书指纹,并将其转换为base64并将其添加到facebook。如果有人需要帮助,请评论

根据Facebook登录Android,你必须提供关键哈希值。为了获得它,您将需要用于签署应用程序的密钥。

keytool \
    -exportcert \
    -alias YourKeyAlias \
    -storepass YourStoreKeyPassword \
    -keystore PathToYourKeyStoreFile | 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

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

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

我通过在MainApplication.onCreate中添加以下内容来修复这个问题:

try {
    PackageInfo info = getPackageManager().getPackageInfo(
                           "com.genolingo.genolingo",
                           PackageManager.GET_SIGNATURES);

    for (Signature signature : info.signatures) {
        MessageDigest md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
        KeyHash.addKeyHash(hash);
    }
}
catch (PackageManager.NameNotFoundException e) {
    Log.e("PackageInfoError:", "NameNotFoundException");
}
catch (NoSuchAlgorithmException e) {
    Log.e("PackageInfoError:", "NoSuchAlgorithmException");
}

然后我将其上传到谷歌开发人员控制台,然后下载了派生的APK,无论出于什么原因,它具有完全不同的键散列。

然后我使用LogCat来确定新的密钥散列,并将其添加到Facebook,就像其他用户所概述的那样。