I have an Android application that need to be able to update the Facebook status of a user. I am using this code to request the appropriate permissions:
public void onClick(DialogInterface dialog, int which) {
final String openPermission = "basic_info";
final String publishPermission = "publish_actions";
Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
Log.d("test", "callback session opened " + session.isOpened() + " " + exception);
if (session.isOpened()) {
Log.d("test", "callback session permissions " + session.getPermissions());
if (session.getPermissions().contains(publishPermission)) {
doUpdateStatus(session, status);
} else {
Session.NewPermissionsRequest newPermRequest = new Session.NewPermissionsRequest(ctx, publishPermission);
session.requestNewPublishPermissions(newPermRequest);
}
}
}
};
Session session = new Session.Builder(ctx)
.setApplicationId(APPLICATION_ID)
.build();
Session.setActiveSession(session);
Log.d("test", "session opened " + session.isOpened());
if (!session.isOpened()) {
Session.OpenRequest openRequest = new Session.OpenRequest(ctx);
openRequest.setPermissions(new String[]{openPermission});
session.addCallback(callback);
session.openForRead(openRequest);
} else {
callback.call(session, session.getState(), null);
}
}
This code works fine, except on the very first attempt of a user (when the user never tried any interaction with my application). In this case, session.getPermissions() just returns [], even after the NewPermissionRequest, which ends in an infinite loop, the program keeping asking for publish_action permission.
How can I make it so that the correct permission is given even at first call?
0 comments:
Post a Comment