Android: Facebook PublishPermissions without retyping password (when using SUPPRESS_SSO)?

孤街浪徒 提交于 2020-01-06 22:53:32

问题


The flow of action on this android app is -

  1. UserX registers on facebook
  2. UserX grants read_permissions
  3. UserX grants publish_permissions
  4. His access_token is stored in our database.
  5. UserX logs out

  6. UserY registers ... [follows same steps]

Since it requires login of multiple users I need to SUPPRESS_SSO (thanks to How to disable Single SIgn On for facebook android app?).

Now in facebook API 3.0, Facebook has made ReadPermissions and PublishPermissions different. I am succesfully asking for both the permissions, but it requires the user to login twice (since SSO is suppressed and webview is displayed) - the login webview pops up once again - the user has to put in his email and password. I want to access the PublishPermissions, or the ReadPermissions (in any order) without the user having to retype his password.

Relevant functions from the java code is shown here:

private static final List<String> PERMISSIONS = Arrays.asList("user_photos", "read_friendlists", "email", "publish_actions", "publish_stream");


private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {
        handleAnnounce();
        textInstructionsOrLink.setText(ACKNOWLEDGE_USER);
        buttonLoginLogout.setText(R.string.logout);
        buttonLoginLogout.setOnClickListener(new OnClickListener() {
            public void onClick(View view) { 
               onClickLogout(); 
            }
        });
    } else {
        textInstructionsOrLink.setText(R.string.login);
        buttonLoginLogout.setText(R.string.login);
        buttonLoginLogout.setOnClickListener(new OnClickListener() {
            public void onClick(View view) { 
                onClickLogin();
            }
        });
    }
}

private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        Session.OpenRequest openRequest = new Session.OpenRequest(this).setCallback(statusCallback);
        List<String> readPermissions = Arrays.asList("user_photos", "email", "read_friendlists");
        openRequest.setPermissions(readPermissions);
        openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        session.openForRead(openRequest);
    } else {
        Session.openActiveSession(this, true, statusCallback);
    }
}


private void requestPublishPermissions(Session session) {
    Log.d(LOG_TAG, "Requesting Publish Permissions...");
    if (session != null) {
        List<String> publishPermissions = Arrays.asList("publish_actions", "publish_stream");
        final int REAUTH_ACTIVITY_CODE = 100;
        Session.NewPermissionsRequest reauthRequest = new Session.NewPermissionsRequest(this, publishPermissions).setRequestCode(REAUTH_ACTIVITY_CODE);
        reauthRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
        session.requestNewPublishPermissions(reauthRequest);
    }
}

private void handleAnnounce() {
    Session session = Session.getActiveSession();
    if (session == null || !session.isOpened()) {
        return;
    }

    List<String> permissions = session.getPermissions();
    if (!permissions.containsAll(PERMISSIONS)) {
        requestPublishPermissions(session);
        return;
    }
}

回答1:


Your code seems to be fine, it's an API's bug recently reported:

https://developers.facebook.com/bugs/268146283318403?browse=search_51235ada57ba59615000124

Just patience, I've got the very same error and all we can do is wait for a fixed API.



来源:https://stackoverflow.com/questions/14000366/android-facebook-publishpermissions-without-retyping-password-when-using-suppr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!