Facebook的会话状态开幕 [英] Facebook session state OPENING

查看:128
本文介绍了Facebook的会话状态开幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以登录到我的应用程序,然后分享的东西。这需要一个打开的会话状态。然而,当我没有登录,然后我想分享的东西,我需要打开的会话。我使用的是ViewPager所以例如当我从一个网页到另一个,这code

I can login to my app then share something. This needs an OPENED session state. However, when I am not logged in, then I want to share something, I need to open the session. I am using a ViewPager so e.g. when I go from one page to another and this code

Session.openActiveSession(getActivity(), true, new StatusCallback() {
       @Override
       public void call(Session session, SessionState state, Exception exception) {
       }
});

是的code开头,那么会变得活跃,而我得到自动登录,这是不对的!这就是为什么我把这个code座到onClickListener,所以我只希望打开会话,如果我点击我的应用程序共享按钮:

is in the beginning of the code, then the session becomes active, and I get automatically logged in, which is wrong! That's why I put this code block into an onClickListener, so I only want to open the session if I click the share button in my app:

if (session != null && session.isOpened()) {
  publishFeedDialog();
}
else {
   Session.openActiveSession(getActivity(), true, new StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
        }
    });
   publishFeedDialog();
}

private void publishFeedDialog() {
  session = Session.getActiveSession();
  Log.i("TAG", session.getState() + ""); //OPENING


  WebDialog feedDialog = (
                    new WebDialog.FeedDialogBuilder(getActivity(),
                        Session.getActiveSession(),
                        params))
                    .setOnCompleteListener(new OnCompleteListener() {

                        @Override
                        public void onComplete(Bundle values,
                            FacebookException error) {
                             if (error == null) {
                                    final String postId = values.getString("post_id");
                                    if (postId != null) {
                                    } else {
                                        // User clicked the Cancel button
                                    }
                                } else if (error instanceof FacebookOperationCanceledException) {
                                } else {
                                    // Generic, ex: network error
                                }
                        }

                    })
                    .build();
                feedDialog.show();
}

错误:

试图使用一个会话没有打开。

Attempted to use a session that was not open.

于是我打开徒劳的会议,因为它仍然是打开当WebDialog应该出现。

So I open the session in vain, because it is still OPENING when the WebDialog should appear.

请帮忙。

推荐答案

尝试从内部调用调用publishFeedDialog()()后检查该会话的状态(不要使用session.isOpened(),使用state.isOpened () 代替)。检查状态确保您会话处于打开状态,并且,它也可以被用于执行请求。该StatusCallback可以调用多次,直到会议实际上是开放的,这就是为什么你要发送的任何请求之前检查状态。

Try calling publishFeedDialog() from inside call() after you check for the status of the session (do not use session.isOpened(), use state.isOpened() instead). Checking the state ensures that your Session is in an open state and that it can also be used to execute requests. The StatusCallback can be called multiple times until the Session is actually open, that is why you should check the status before sending any request.

这篇关于Facebook的会话状态开幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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