Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Android SDK 3.0 callback not called on cancel

I'm trying to upgrade an existing app/framework with Facebook Android SDK v3.0 but am stuck on how to authenticate with extra permissions.

The problem is that the StatusCallback does not seem to fire if the user cancels. If I use the regular call to Session.openActiveSession the callback fires on cancel, but using a new Session.OpenRequest on fresh Session object does not.

Here's my code:

Session.OpenRequest auth = new Session.OpenRequest(this);

String[] permissions = {"publish_stream", "user_status"};

auth.setPermissions(Arrays.asList(permissions));

auth.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

auth.setCallback(new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        switch(state) {

            case OPENING:
                System.out.println("OPENING");
                break;              

            case OPENED: // <-- NOT CALLED
                System.out.println("OPENED");
                break;

            case CREATED: // <-- NOT CALLED
                System.out.println("CREATED");
                break;

            case CREATED_TOKEN_LOADED: // <-- NOT CALLED
                System.out.println("CREATED_TOKEN_LOADED");
                break;

            case OPENED_TOKEN_UPDATED: // <-- NOT CALLED
                System.out.println("OPENED_TOKEN_UPDATED");
                break;

            case CLOSED: // <-- NOT CALLED
                System.out.println("CLOSED");
                break;      

            case CLOSED_LOGIN_FAILED: // <-- NOT CALLED
                System.out.println("CLOSED_LOGIN_FAILED");
                break;                          
        }
    }
});

Session session = new Session.Builder(this).setApplicationId("<My APP ID>").build();
session.openForPublish(auth);

This produces a view on the device like this:

http://cl.ly/image/0E2C0t2m2b0g

(FB app is not installed). If the user clicks the close button (top left) the callback is NOT triggered.

If I use the Session.openActiveSession in the same scenario the callback IS triggered.

Is this a bug, or am I doing something wrong?

Thanks!

like image 861
Jason Polites Avatar asked Dec 06 '25 08:12

Jason Polites


1 Answers

Found the problem. When creating a session manually, one must set this session as the "active session" on the static Session instance:

Session session = new Session.Builder(this).setApplicationId("<My APP ID>").build();
Session.setActiveSession(session); // <-- MUST DO THIS
session.openForPublish(auth);
like image 154
Jason Polites Avatar answered Dec 08 '25 22:12

Jason Polites



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!