Facebook SSO 示例不起作用 - “发生错误。请稍后重试”
我正在尝试将 facebook 集成到我的应用程序中,因此遵循了以下教程: Facebook Android 但我无法让第一个示例(单点登录)工作。当我的应用程序加载时,我会看到 Facebook 对话框,但它只是显示“发生错误。请稍后再试。”底部有一个 facebook 风格的“Ok”按钮,logcat 中没有任何内容:
我按照教程中的步骤操作,但我猜测 APP ID 或hashkey由keytool生成。以下是我遵循的步骤:
- 克隆 fb git。
- 创建fbSDK项目。
- 创建自己的 fb 项目并将 fbSDK 作为库链接。
- 然后,我使用 openssl 执行 keytool cmd,并按照 stackoverflow 上其他人的建议输入密码“android”。
- 我访问developers.facebook.com并创建了一个新应用程序。
- 在“编辑设置 -> 移动和设备”中,我将哈希值放入提供的框中。
- 在“编辑设置 -> 移动和设备”中,我选择“本机应用程序”作为“应用程序类型”。
- 回到应用程序中,我复制并粘贴了 SSO 示例代码。
- 我将 Facebook() 构造函数中的“YOUR_APP_ID”更改为新应用程序的 Developers.facebokk.com 页面上显示的 APP ID。
- 我在手机上运行了该应用程序。
我不知道为什么 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:
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:
- clone fb git.
- create fbSDK project.
- create own fb project and link the fbSDK as a library.
- I then did the keytool cmd with openssl and input the password "android" as suggested by others on stackoverflow.
- I went to developers.facebook.com and created a new app.
- In "Edit Settings->Mobile and Devices" I put my hash in the box provided.
- In "Edit Settings->Mobile and Devices" I chose "Native App" as "Application Type"
- Back in the app I copy and pasted the SSO example code.
- 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.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须从单独的线程调用 .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!".)
事实上我也遇到过同样的问题并且解决了。
因此,在哈希密钥生成中,请使用以下步骤:
keytool -exportcert -alias androiddebugkey -keystore [您的 SDK 路径 |例如 c:\users\user].android\debug.keystore | openssl sha1 - 二进制 | openssl base64
In fact I have encountered the same problem exactly and it solved.
So, in the hash key generation use the following steps:
keytool -exportcert -alias androiddebugkey -keystore [your SDK path | e.g c:\users\user].android\debug.keystore | openssl sha1 -binary | openssl base64
我遇到这个问题只是因为我在使用正确的密钥正确初始化 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.
您在第 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.
正确找出哈希值的最佳方法是这段代码:
将 com.facebook.samples.loginhowto 替换为您自己的包名称。
The best way to correctly find out your hash is this lil piece of code.:
Replace com.facebook.samples.loginhowto with your own package name.