I am trying to give users the ability to set / cancel permission to publish through the checkbox (Facebook SDK for Android). The code is below. Everything works fine, except that after the revocation of the code responsible for checking the permissions to publish, the failure subsided.
I understand that the session does not know if the user can revoke any permissions after logging in. What is the right way to deal with this situation? Should I request available permissions manually or is there a way to seamlessly recreate a session with basic permissions?
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ... publishCheckbox = (CheckBox) view.findViewById(R.id.publishCheckbox); publishCheckbox.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { CheckBox chb = (CheckBox) v; if (chb.isChecked() && checkForPublishPermission() == false){ requestPublishPermissions(); } else{ removePublishPermissions(); } } }); ... } private void requestPublishPermissions() { Session session = Session.getActiveSession(); if ( session!= null && session.isOpened()){ Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS).setRequestCode(REAUTH_ACTIVITY_CODE); newPermissionsRequest.setCallback(callback); session.requestNewPublishPermissions(newPermissionsRequest); } } private void removePublishPermissions() { Request r = new Request(Session.getActiveSession(), PUBLISH_ACTIONS_PERMISSION_PATH, null, HttpMethod.DELETE); r.setCallback(new Request.Callback() { @Override public void onCompleted(Response response) { publishCheckbox.setEnabled(true); } }); r.executeAsync(); publishCheckbox.setEnabled(false); } private boolean checkForPublishPermission(){ boolean result = false; Session session = Session.getActiveSession(); if (session == null || !session.isOpened()) { result = false; } else{ List<String> permissions = session.getPermissions(); if (permissions.containsAll(PERMISSIONS)) { result = true; } } return(result); } private void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { ... publishCheckbox.setChecked(checkForPublishPermission()); ... } else if (state.isClosed()) { ... } }
source share