简体   繁体   English

适用于Android 3.0的Facebook维护会话

[英]Facebook for Android 3.0 Maintain session

I have a viewpager and ActionBarSherlock. 我有一个viewpager和ActionBarSherlock。 In the menu of the actionbar I placed a button "Log In" that takes me to a login screen (this is the same as the one in the tutorial ). 在操作栏菜单中,我放置了一个“登录”按钮,该按钮将我带到登录屏幕(与本教程中的屏幕相同)。 This login works fine, every time I open the app, I don't need to login again. 此登录工作正常,每次打开应用程序时,无需再次登录。 What I want is to change this "Log in" menu item to "Log out" when the session is open. 我要的是在会话打开时将此“登录”菜单项更改为“注销”。 But the session is alwasy null. 但是会话是空的。 Not the state of the session, but the session itself . 不是会话的状态,而是会话本身 Why? 为什么?

   Session session = Session.getActiveSession();
   if (session == null) {

   } else {
      publishStory();
   }

What am I missing here? 我在这里想念什么? Do I need some other code, or should this be enough? 我是否需要其他代码,还是应该足够?

Because you need to open the active session before you can write Session.getActiveSession() . 因为您需要先打开活动会话,然后才能编写Session.getActiveSession() And don't forget to define session outside: 并且不要忘记在外部定义session

Session.openActiveSession(getActivity(), true, new StatusCallback() {

                @Override
                public void call(Session session, SessionState state, Exception exception) {
                }
            });
session = Session.getActiveSession();

You can learn more about the related openActiveSession method here: 您可以在此处了解有关相关的openActiveSession方法的更多信息:

https://developers.facebook.com/docs/reference/android/current/Session https://developers.facebook.com/docs/reference/android/current/Session

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM