Facebook SDK 3 - Session Re-log in issue

I'm using Facebook login as described in the "Getting started" Document - https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

 // start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {

  // callback when session changes state
  @Override
  public void call(Session session, SessionState state, Exception exception) {
    if (session.isOpened()) {

      // make request to the /me API
      Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

        // callback after Graph API response with user object
        @Override
        public void onCompleted(GraphUser user, Response response) {
          if (user != null) {
            TextView welcome = (TextView) findViewById(R.id.welcome);
            welcome.setText("Hello " + user.getName() + "!");
          }
        }
      });
    }
  }
});

when using this code Facebook recognize the user (that loged-in in the Facebook app) and assumes that this is the user that I want to log in with.

let's say that I want to leave the decision what Facebook account to use to the user. how can I do that?

things I've tried so far:

1)perform user log in like this:

 SessionTracker sessionTracker = new SessionTracker(activity, new StatusCallback() {

            @Override
            public void call(Session session, SessionState state, Exception exception) {
            }
        }, null, false);

        if (sessionTracker.getSession() == null || sessionTracker.getSession().getState().isClosed()) {
            sessionTracker.setSession(null);
            Session session = new Session.Builder(activity).setApplicationId(activity.getString(R.string.fb_app_id)).build();
            Session.setActiveSession(session);
        }

        final Session currentSession = sessionTracker.getSession();

        if (!currentSession.isOpened()) {

            Session.OpenRequest openRequest = null;
            openRequest = new Session.OpenRequest(activity);

            if (openRequest != null) {
                openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
                openRequest.setPermissions(Arrays.asList("email", "publish_actions"));
                openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
                openRequest.setCallback(new StatusCallback() {

                    @Override
                    public void call(Session session, SessionState state, Exception exception) {

                        Request.executeMeRequestAsync(currentSession, new Request.GraphUserCallback() {

                            @Override
                            public void onCompleted(GraphUser user, Response response) {
                                authListener.onCompleteAuthorization(user != null, user, currentSession.getAccessToken(), currentSession.getExpirationDate().getTime());
                            }
                        });

                    }
                });
                currentSession.openForPublish(openRequest);

this works fine for the first time, but second time been called (Let's say after user loggin out from my app, and want to re-login with another facebook account) it remembers the last user that was logged in. !!even after uninstall Facebook app and my app!!!!

2) calling the same code before log in again:

 if (Session.getActiveSession() != null) {
            Session.getActiveSession().closeAndClearTokenInformation();
        }

it does not do anything...

please help me understand how can I clear all previous Facebook user history / cached tokens, to achieve the following behavior: every time user perform Facebook login - Facebook "enter Email + password" dialog will appear...

thanks in advance..

Answers


First of all, do not use SessionTracker directly. It's not a public class, and is not meant to be consumed directly.

Secondly, if you want to pop up the email/password dialog every time, you need to disable SSO login. You can have a look inside the SwitchUserSample for how to do it with multiple sessions, but here's the gist of it:

Session s = new Session(this);
Session.setActiveSession(s);
Session.OpenRequest request = new Session.OpenRequest(this);
request.setPermissions(...); // Note that you cannot set email AND publish_actions in the same request
request.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
request.setCallback(...);
s.openForRead(request);

Some time later, in your callback, you should check if the session is opened, and if it contains the publish_actions permission, and if not request additional publish permissions (see the Scrumptious sample for an example).

Lastly, when the user logs out, call the closeAndClearTokenInformation() method as you've done previously. Since you're forcing dialog login now, it will work as you expect it to.


Need Your Help

run python script from command line and then enter interactive mode

python command-line

Is there a way to run a python module from command line ( -m option, which imports and runs a module ), and then enter the interactive mode?