Facebook SDK v3.5.2 - Request Permissions from a Private Session

When the user clicks the cancel button, he closes the facebook session.

Facebook Access Request Dialog: http://imgur.com/2PiYGrK

I am trying to request permission for a session that was apparently closed when the user clicked the Cancel button in the "Request Facebook Permissions" dialog box. When I try to open an ActiveSession without requestNewReadPermissions, only basic permissions are requested, but when I do this, I get this error:

E / AndroidRuntime (12619): java.lang.UnsupportedOperationException: session: An attempt was made to request new permissions for a closed session.

Below is the code from the SDK v3.5.2 example for LoginUsingActivityActivity.java added by me:

Session.NewPermissionsRequest request = new Session.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewReadPermissions(request);

Here is the code:

private static final List<String> PERMISSIONS = Arrays.asList("user_birthday", "user_friends","user_hometown","user_location","email");

private void onClickLogin() {
        Session session = Session.getActiveSession();
        if (!session.isOpened() && !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(PERMISSIONS));
        } else {
            Session.openActiveSession(this, true, statusCallback);
            Session.NewPermissionsRequest request = new Session.NewPermissionsRequest(this, PERMISSIONS);
            session.requestNewReadPermissions(request);
        }
    }

I was looking for a solution and, apparently, I had to destroy the current session and create a new one. This works, but I think this is bad code. Is there another way to resume a session and request new permissions?

private void onClickLogin() {
        Session session = Session.getActiveSession();
        if (!session.isOpened() && !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(PERMISSIONS));
        } else {
            session.closeAndClearTokenInformation();
            session = null; 
            session = new Session(this);

            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setPermissions(PERMISSIONS));
        }
    }
+4
source share
1 answer

I had to make many workarounds to do this, I will not recommend you to continue this way, the new SDK has some callbacks that are not ideal, but they will work for what you are trying to achieve:

https://developers.facebook.com/docs/android/upgrading-4.x

, SDK, , .

+1

All Articles