Home How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?
Reply: 0

How to programmatically log out from Facebook SDK 3.0 without using Facebook login/logout button?

user1958 Published in April 24, 2018, 8:29 am

The title says it all. I'm using a custom button to fetch the user's facebook information (for "sign up" purposes). Yet, I don't want the app to remember the last registered user, neither the currently logged in person via the Facebook native app. I want the Facebook login activity to pop up each time. That is why I want to log out any previous users programmatically.

How can I do that? This is how I do the login:

private void signInWithFacebook() {

    SessionTracker sessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() 
        public void call(Session session, SessionState state, Exception exception) { 
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    mCurrentSession = sessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        mCurrentSession = session;

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(RegisterActivity.this);

        if (openRequest != null) {

    }else {
        Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {
              public void onCompleted(GraphUser user, Response response) {
                  fillProfileWithFacebook( user );

Ideally, I would make a call at the beginning of this method to log out any previous users.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.348788 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO