Facebook状态回调不适用于片段
Posted
技术标签:
【中文标题】Facebook状态回调不适用于片段【英文标题】:Facebook Status call back not working with fragment 【发布时间】:2015-03-25 17:08:44 【问题描述】:我正在尝试在成功登录的片段中使用 SFB 登录回调(fb 显示应用已授权)但回调不起作用。 当我尝试使用 Activity 相同的代码时,它可以工作。如果出现碎片,我是否遗漏了什么?
public void faceBook(View view)
if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG))
// Publish the post using the Share Dialog - This is working.
//When FB not installed else part will execute - There I have issue
else
Session session = Session.getActiveSession();
if(!session.getState().isOpened())
//here am setting the status call back as third parameter "this" and implemented Session.status call back in my class which is extended a fragment
//so publishFeedDialog did not get called after login
Session.openActiveSession(this, true, this);
else
publishFeedDialog(session);
@Override
public void call(Session session, SessionState sessionState, Exception e)
//A call supposed to come here after user sign to fb, but that is not happening. (fb shows app as authorized) but callback doesn't work. When I am trying same code with Activity it works
if(session.getState().isOpened())
publishFeedDialog(session);
【问题讨论】:
也许添加一些代码,然后我们将能够决定您是否遗漏了什么 【参考方案1】:我查看了 facebook Session 类,发现有另一个版本的 Session.openActiveSession() 可以从片段中使用
openActiveSession(context, fragment, allowLoginUI, statusCallback);
确保片段是 android.support.v4.app.Fragment
【讨论】:
以上是关于Facebook状态回调不适用于片段的主要内容,如果未能解决你的问题,请参考以下文章