问题
The flow of action on this android app is -
- UserX registers on facebook
- UserX grants read_permissions
- UserX grants publish_permissions
- His access_token is stored in our database.
UserX logs out
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