Facebook Android SDK Session openForPublish does not create a new session

In the Android Android SDK when I call

Session tempSession = new Builder(this).build();
Session.setActiveSession(tempSession);
tempSession.openForRead(new OpenRequest(this).setPermissions(FB_PERMISSIONS));

He gets an FB session, and every thing works as usual. But when I replace Readwith Publish. those. should

Session tempSession = new Builder(this).build();
Session.setActiveSession(tempSession);
tempSession.openForPublish(new OpenRequest(this).setPermissions(FB_PERMISSIONS));

It gives an error saying that the session is empty and cannot obtain publish permissions for an empty session.

Could you tell us why this is so and what would be the best way to handle this?

+5
source share
2 answers

Short answer: do not call openForPublish. Call openForRead and then requestNewPublishPermissions later if you need to publish permissions.

, ( , Facebook ), ( , openForRead ). , openForPublish , , , .

+4

, , , Facebook . , , , . / . , , , :

Session session = Session.getActiveSession();

if (session == null) {
    session = new Session.Builder(this).setApplicationId("<APP ID HERE>").build();

    Session.setActiveSession(session);
    session.addCallback(new StatusCallback() {
        public void call(Session session, SessionState state, Exception exception) {
            if (state == SessionState.OPENED) {
                Session.OpenRequest openRequest = new Session.OpenRequest(FacebookActivity.this);
                openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
                session.requestNewPublishPermissions(
                        new Session.NewPermissionsRequest(FacebookActivity.this, PERMISSIONS));
            }
            else if (state == SessionState.OPENED_TOKEN_UPDATED) {
                publishSomething();
            }
            else if (state == SessionState.CLOSED_LOGIN_FAILED) {
                session.closeAndClearTokenInformation();
                // Possibly finish the activity
            }
            else if (state == SessionState.CLOSED) {
                session.close();
                // Possibly finish the activity
            }
        }});
}

if (!session.isOpened()) {
    Session.OpenRequest openRequest = new Session.OpenRequest(this);
    openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
    session.openForRead(openRequest);
}
else
    publishSomething();
+7

All Articles