Facebook SSO 示例不起作用 - “发生错误。请稍后重试”

发布于 2024-10-20 07:21:14 字数 1210 浏览 1 评论 0原文

我正在尝试将 facebook 集成到我的应用程序中,因此遵循了以下教程: Facebook Android 但我无法让第一个示例(单点登录)工作。当我的应用程序加载时,我会看到 Facebook 对话框,但它只是显示“发生错误。请稍后再试。”底部有一个 facebook 风格的“Ok”按钮,logcat 中没有任何内容: App shown Facebook error

我按照教程中的步骤操作,但我猜测 APP ID 或hashkey由keytool生成。以下是我遵循的步骤:

  1. 克隆 fb git。
  2. 创建fbSDK项目。
  3. 创建自己的 fb 项目并将 fbSDK 作为库链接。
  4. 然后,我使用 openssl 执行 keytool cmd,并按照 stackoverflow 上其他人的建议输入密码“android”。
  5. 我访问developers.facebook.com并创建了一个新应用程序。
  6. 在“编辑设置 -> 移动和设备”中,我将哈希值放入提供的框中。
  7. 在“编辑设置 -> 移动和设备”中,我选择“本机应用程序”作为“应用程序类型”。
  8. 回到应用程序中,我复制并粘贴了 SSO 示例代码。
  9. 我将 Facebook() 构造函数中的“YOUR_APP_ID”更改为新应用程序的 Developers.facebokk.com 页面上显示的 APP ID。
  10. 我在手机上运行了该应用程序。

我不知道为什么 logcat 中没有任何内容,但是当我安装它时,控制台总是毫无失败地显示:ActivityManager: 警告: Activity 未启动,其当前任务已被带到前面

我找不到对我的应用程序的任何 logcat 引用,也找不到从 facebook sdk 收到的错误:Facebook-ProxyAuth(4828): 无法读取调用包的签名。

我一直在现在已经花了几个小时了,任何帮助将不胜感激。我不敢相信 facebook SDK 和帮助对于 Android 来说是如此粗略,facebook 应该为自己感到羞耻。

谢谢,

英菲尼迪菲兹

I'm trying to integrate facebook into my app and so have followed the tutorial at: Facebook Android but I can't get the first example (Single Sign-On) to work. When my app loads up I get the facebook dialog but it just says "An error occurred. Please try again later." with a facebook-style "Ok" button at the bottom and there is nothing in logcat:
App showing Facebook error

I followed the steps in the tutorial but I'm guessing there is something wrong with the APP ID or the hashkey generated by keytool. Here are the steps I followed:

  1. clone fb git.
  2. create fbSDK project.
  3. create own fb project and link the fbSDK as a library.
  4. I then did the keytool cmd with openssl and input the password "android" as suggested by others on stackoverflow.
  5. I went to developers.facebook.com and created a new app.
  6. In "Edit Settings->Mobile and Devices" I put my hash in the box provided.
  7. In "Edit Settings->Mobile and Devices" I chose "Native App" as "Application Type"
  8. Back in the app I copy and pasted the SSO example code.
  9. I changed the "YOUR_APP_ID" in the Facebook() constructor to the APP ID shown on the developers.facebokk.com page for my new app.
  10. I ran the app on my phone.

I don't know why there is nothing in logcat but when I install it, the Console always, without fail, says the:ActivityManager: Warning: Activity not started, its current task has been brought to the front

And I can't find any logcat reference to my app or the error I was getting from the facebook sdk which was: Facebook-ProxyAuth(4828): Failed to read calling package's signature.

I have been at this for a few hours now and any help would be greatly appreciated. I can't believe the facebook SDK and help is so sketchy for Android, facebook should be ashamed of themselves.

Thanks,

InfinitiFizz

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

想念有你 2024-10-27 07:21:14

您必须从单独的线程调用 .request() 。如果您在 UI 线程上执行此操作,则 facebook 授权不会在您的代码执行之前完成。所以在facebook授权的“onComplete”中调用新线程。此时您将拥有有效的访问令牌。祝你好运!

(这就是为什么 api 说“不要从 UI 线程调用它!”。)

You have to call .request() from a separate thread. If you do it on the UI thread the facebook authorize doesn't complete before your code executes. So call the new thread in the "onComplete" of facebook authorization. You'll have a valid access token at this point. Good luck!

(this is why the api says "don't call this from the UI thread!".)

開玄 2024-10-27 07:21:14

事实上我也遇到过同样的问题并且解决了。
因此,在哈希密钥生成中,请使用以下步骤:

  1. 打开 cmd 并转到您的 android SDK 路径。
  2. 输入这个命令:
    keytool -exportcert -alias androiddebugkey -keystore [您的 SDK 路径 |例如 c:\users\user].android\debug.keystore | openssl sha1 - 二进制 | openssl base64
  3. 之后它的 promet 密码输入“android”
  4. 将结果复制到您的 Facebook 应用程序设置并保存设置。
  5. 在您的 Android 应用程序中使用 facebook 应用程序 ID(而不是 Android 哈希密钥)。

In fact I have encountered the same problem exactly and it solved.
So, in the hash key generation use the following steps:

  1. open cmd and go to your android SDK path.
  2. type this command :
    keytool -exportcert -alias androiddebugkey -keystore [your SDK path | e.g c:\users\user].android\debug.keystore | openssl sha1 -binary | openssl base64
  3. after that it's promet for password enter "android"
  4. copy the result to your facebook app settings and save settings.
  5. in your android app use the facebook app id(not the android hash key).
断爱 2024-10-27 07:21:14

我遇到这个问题只是因为我在使用正确的密钥正确初始化 facebook 对象之前调用了 facebook api。只需确保您使用正确的密钥并且正确初始化 Facebook 对象即可。

另外,我也曾因尝试使用不同的 Android 应用程序密钥进行 facebook api 调用而被绊倒过几次。请记住,Facebook 教程指导您使用编译的 apk 创建密钥。如果您要从 IDE 运行代码(我使用的是 Eclipse),则此密钥散列将会有所不同。当您直接从 eclipse 运行您的应用程序时,facebook 密钥将会有所不同,因为当您从 eclipse 运行您的应用程序时,它使用默认的发布密钥来构建您的应用程序。

因此,我通常在 Facebook 开发者门户中拥有两个密钥。一个密钥是使用 Android 市场使用的发布密钥编译的 apk 创建的,另一个密钥是通过直接从 eclipse 运行应用程序代码创建的。

I had this problem simply because I was making calls to the facebook api before I properly initialized the facebook object with the correct key. Just make sure you're using the right key and you're initializing the Facebook object properly.

Also, I've also been tripped up a few times by attempting to make facebook api calls with a different android application key. Keep in mind that the facebook tutorial instructs you to create your key with a compiled apk. This key hash will be different if you're going to run your code from the IDE (i'm using Eclipse). When you run your app directly from eclipse the facebook key will be different because when running your app from eclipse it's using a default release key to build your app.

Because of this I usually have two keys in the facebook developer portal. One key that was created with an apk compiled with the release-key used for the Android market and another key that was created from running the app code directly from eclipse.

天涯沦落人 2024-10-27 07:21:14

您在第 7 步中选择 Native App 的原因是什么?我将其保留在默认的 HTML5/移动网络中,并让示例正常工作。

Any reason you selected Native App in step 7? I left it at the default HTML5 / mobile web and got the sample to work.

硬不硬你别怂 2024-10-27 07:21:14

正确找出哈希值的最佳方法是这段代码:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.loginhowto", 
                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) {

    }
    ...

将 com.facebook.samples.loginhowto 替换为您自己的包名称。

The best way to correctly find out your hash is this lil piece of code.:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.facebook.samples.loginhowto", 
                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) {

    }
    ...

Replace com.facebook.samples.loginhowto with your own package name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文