Android的Facebook的SDK 3.0身份验证 [英] Android Facebook SDK 3.0 auth

查看:960
本文介绍了Android的Facebook的SDK 3.0身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我下面从Facebook SDK样本SessionLoginFragment.java例子。

I'm actually following SessionLoginFragment.java example from facebook sdk samples.

我真的不明白是这样的:

What I really don't understand is this:

当我把

session.openForRead(new Session.OpenRequest(fragment).setCallback(statusCallback));

登录我的用户给Facebook,并要求基本的读取权限(只是为了测试整合)它根本不起作用。

to log my user to facebook and ask basic read permission (just to test the integration) it simply does not work.

我挖了一下使用调试器,我遵循的道路。如果你不把一个请求,code到会话的OpenRequest它将给它一个随机的(这是确定)。

I digged a bit with the debugger and I followed the path. If you don't put a requestCode to the OpenRequest of the session it will give it a random one (and this is ok).

openForRead(我的实际会话中创建的状态),将创建权限对话框。当你点击确定按钮,它会执行

openForRead (my actual session is in CREATED status) will create the permission dialog. When you hit the "Ok" button it will perform a

request.getStartActivityDelegate().startActivityForResult(intent, request.getRequestCode());

您可以看到从FB SDK源$ C ​​$ c中的code。那么请求code是相同的会话(这里是确定)。

You can see the code from the fb sdk source code. Well the requestCode is the same of the session (and here's ok).

在FB让您登录到系统中,将完成他的facebook.LoginActivity,叫我回来我onActivityResult在我的活动。的问题是,在这里的请求code是从请求的不同。我不知道为什么和它从何而来!

When fb log you into the system it will finish his facebook.LoginActivity and call me back my onActivityResult in my activity. The problem is that here the requestCode is different from the request's one. And I don't know why and where it comes from!

如果我进入我的FB账号我的应用程序在那里,所以这意味着我已经做了很好完成了正确的身份验证流程。但是,我不会得到正确验证从我的应用程序,因为这个问题。

If I go into my fb account my application is there, so it means that I've done the correct auth flow that finish well. But I wont get correctly authenticated from my app because of this problem.

你知道为什么,我该如何解决呢?

Do you know why and how can I solve it?

感谢。

更新具有流动详细信息:

UPDATE WITH FLOW DETAIL:

这是实际的流程(从片段):

This is the actual flow (from fragment):

session.openForRead(new Session.OpenRequest(fragment).setCallback(statusCallback));

创建后,请求code是(总是) 64206 现在openForRead流将调用(最后部分)

After creating it, the request code is (always) 64206 Now openForRead flow will call (final part)

request.getStartActivityDelegate().startActivityForResult(intent, request.getRequestCode());

这是调用从Facebook SDK的LoginActivity,做客户机/服务器验证/ OAuth的

That call the LoginActivity from facebook SDK and do the client/server validation/oauth

现在我的活动叫onActivityResult(不是片段,但在活动的一部分)

Now on my activity is called onActivityResult (not on the fragment but on the activity part)

在这里我叫

Session.getActiveSession().onActivityResult(activity, requestCode, resultCode, data);

在这里请求code是要求code 129742

这怎么可能?正如我已经说过,在所有这些流动的问题是,要求code回到onActivityResult是从我pendingRequest请求code不同的,这种突破(getActiveSession()函数。onActivityResult返回而不执行code)登录客户端部分。

How is it possible? As I already said, the problem in all this flow is that requestCode returned to onActivityResult is different from my pendingRequest requestCode and this break (getActiveSession().onActivityResult return without executing code) the login client part.

推荐答案

我遇到了同样的问题,但在我的情况下,违规请求code 326350 0x4face )。而我确实是叫 super.onActivityResult ,所以解决方法提出了埃里克·萨维奇已经到位,但没有效果。所有的最奇特的地方,这东西没有工作,只是一个几个星期前,和犯罪行为出现没有自己的任何升级(Facebook的SDK版本,Android版本,支持库版本,甚至在我正在开发/测试的手机,是所有的一样,当我有它的工作)。

I ran into the same problem, except that in my case the offending requestCode was 326350 (0x4face). And I was indeed calling super.onActivityResult, so the workaround proposed by Eric Savage was already in place but not effective. Weirdest thing of all, this stuff did work just a couple of weeks ago, and the offending behaviour appeared without myself upgrading anything (Facebook SDK version, Android version, support library version, even the phone on which I'm developing/testing, are all the same as when I had it working).

不过,Eric的回答包含了其他有趣的提示,这是我利用来再次让我的code的工作。而不是整个请求code 传递给 Session.onActivityResult 基本上,我切的最低16位,通过这些而已。

However, Eric's answer contains other interesting hints, which I exploited to make my code work again. Basically, instead of passing the whole requestCode to Session.onActivityResult, I cut the lowest 16 bits and pass those only.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session session = Session.getActiveSession();
    int sanitizedRequestCode = requestCode % 0x10000;
    session.onActivityResult(this, sanitizedRequestCode, resultCode, data);
}

我相信这是一个应该被固定在Facebook的SDK中的错误,并且会坚持要把它修补了下一个版本。

I do believe this is a bug that should be fixed in the Facebook SDK, and would insist to have it patched for the next release.

这篇关于Android的Facebook的SDK 3.0身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆