Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session.openActiveSession only calls OPENING in Facebook Android SDK

I am trying to login with Facebook using the Facebook Android SDK, however, the status callback is fired only once with OPENING session state. After that, a Facebook login activity appears with no content (I know it's that activity as it has the title that I've set for title_facebook_login in strings.xml) for a brief moment and disappears within a second. No other callback is fired, no exceptions, no crashes. It just waits forever at my initial activity. Here is my code:

Session.openActiveSession(parent, true, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if(state == SessionState.OPENED){
                String accessToken = session.getAccessToken();
            }
        }
    });

Why wouldn't the callback fire for SessionState.OPENED (or CREATED, or even CLOSED) but only OPENING?

like image 477
Can Poyrazoğlu Avatar asked Jan 10 '23 17:01

Can Poyrazoğlu


1 Answers

You need to call onActivityResult

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
    }

So when login done . It comes to same activity and calls status callback with session state is opened

initialize UiLifecycleHelper

private UiLifecycleHelper uiHelper;

in oncreate need to call before setContentView

uiHelper = new UiLifecycleHelper(this, statusCallback);
        uiHelper.onCreate(savedInstanceState);

and need to maintain session in

    @Override
    protected void onResume() {
        super.onResume();
        uiHelper.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }
like image 76
Tulsiram Rathod Avatar answered Jan 17 '23 07:01

Tulsiram Rathod