Android Facebook SDK 3.0认证 [英] Android Facebook SDK 3.0 auth

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

问题描述

我实际上是从facebook sdk示例中跟随SessionLoginFragment.java示例。



我真的不明白是这样的:



当我做

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

将我的用户记录到Facebook并提出基本的读取权限(只是测试集成),它只是不工作。



我用调试器挖了一下,我按照路径。如果您没有将请求代码放在会话的OpenRequest中,它将给它一个随机的(这样可以)。



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

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

您可以从fb sdk源代码中看到代码。那么requestCode与会话相同(这里没关系)。



当fb登录系统时,将完成他的facebook.LoginActivity,并在我的活动中打电话给我的onActivityResult。问题是这里requestCode与请求的不同。我不知道为什么和它来自哪里!



如果我进入我的fb帐户,我的应用程序在那里,所以这意味着我已经完成了正确的验证流程。但是,由于这个问题,我的应用程序不能正确地进行身份验证。



你知道为什么,怎么解决?



谢谢。



更新流程细节:



这是实际流程(来自 fragment ):

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

创建后,请求代码为(总是) 64206
现在openForRead流程将调用(最后一部分)

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

从facebook SDK调用LoginActivity并执行客户端/服务器验证/ oauth



现在我的活动被称为onActivityResult(不在片段上,而在活动部分)



在这里我调用

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

这里requestCode为requestCode 129742



怎么可能?正如我已经说过的,所有这一切的问题是,requestCode返回到onActivityResult不同于我的pendingRequest requestCode和这个break(getActiveSession()。onActivityResult返回而不执行代码)登录客户端部分。

解决方案

我遇到同样的问题,除了在我的情况下,有罪的 requestCode 326350 0x4face )。而我确实在调用 super.onActivityResult ,所以 Eric Savage提出的解决方法已经到位但没有效果。最奇怪的是,这些东西在几周前就起作用了,而且没有自己升级任何东西(Facebook SDK版本,Android版本,支持图书馆版本,甚至是我正在开发/测试的手机)都会出现违规行为但是,Eric的答案包含其他有趣的提示,我利用这些提示使我的代码再次工作。基本上,我把最低的16位和最低16位通过,而不是将整个 requestCode 传递给 Session.onActivityResult

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

我确实相信这是一个应该在Facebook SDK中修复的错误,并将坚持在下一个版本中修补。


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

What I really don't understand is this:

when I make

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

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

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 (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());

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

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!

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?

Thanks.

UPDATE WITH FLOW DETAIL:

This is the actual flow (from fragment):

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

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

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

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

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

and here I call

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

And here the requestCode is requestCode 129742

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.

解决方案

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).

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);
}

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天全站免登陆