I'm trying to figure out how new API works, so I've managed to understand the concept, and managed to do my own "hello world", that log on to facebook, log out and try to upload image.
Now in both HelloFacebookSample and SessionLoginSimple, there is a simple login to facebook, and in the HelloFacebookSample, when you click "Post photo", a new dialog for login appears, because the permissions are not set.
this is the code from HelloFacebookSample:
private void performPublish(PendingAction action) {
Session session = Session.getActiveSession();
if (session != null) {
pendingAction = action;
if (session.getPermissions().contains("publish_actions")) {
// We can do the action right away.
handlePendingAction();
} else {
// We need to reauthorize, then complete the action when we get called back.
Session.ReauthorizeRequest reauthRequest = new Session.ReauthorizeRequest(this, PERMISSIONS).
setRequestCode(REAUTHORIZE_ACTIVITY).
setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
session.reauthorizeForPublish(reauthRequest);
}
}
}
So as we do not have "publish_actions" we need to reauthorize.
In SimpleSessionLogin login looks like this:
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(this, true, statusCallback);
}
}
So, I can't figure out how to request permissions during login. It's kind a weird or to say redundant to log in to the service twice in couple of seconds with exactly the same dialog.
It can sound to user that something is wrong or weird.
I want to log to facebook once, with wanted permissions, but using API 3.0 Session calls, not the deprecated one.
Can anyone please explain how?
The Session.OpenRequest has a method where you can set permissions. However, with the 3.0 SDK, Facebook is now requesting that developers request "read" and "publish" permissions separately. So if your app needs to both read user info and publish on their behalf, then you'll need to call reauthorize.