In previous android SDK, I asked new permission by calling Facebook.authorize() and it showed approving permission screen. But in SDK 3.0, when I call FacebookActivity.openSessionForPublish() , dialog always shows login form. How can I show approving permission screen?
I’ve set up session that has token and expiration date and its SessionState is CREATED_TOKEN_LOADED .
Is there any requirement for showing permission dialog or does Facebook.authorize() always show login form? Then please teach me right method for that.
My code is like below
public class FbConn extends FacebookActivity {
public void onCreate(Bundle savedInstanceState) {
...
if( savedInstanceState == null ) {
Session savedSession = CommonUtil.getFbSession(CustomSessionStore.getFbInfo(getApplicationContext())); //get access token and expiration date from session store and set up new session.
Session.setActiveSession(savedSession);
setSession(savedSession);
}
}
protected void onStart() {
super.onStart();
openSessionForPublish(EpisodeApplication.config.getSelectedServer().fbAppId, Constants.FB_PERMISSIONS);
}
}
Update
I’ve commented out these lines and permission request screen showed successfully. But I don’t sure this is right way or not.
In com.facebook.LoginActivity line 62,
Utility.clearFacebookCookies(this);
In com.facebook.Session line 1202,
Utility.clearFacebookCookies(getStaticContext());
If you already have a valid session, from a previous auth flow, then if you want to request new permissions then use the Session.ReauthorizeRequest class.
This should show a permissions screen for the new permissions you’re asking for instead of the login form.
However, from looking at your logic it is not clear where you’re handling the first time login. If you expect to handle it in this class then I suggest using the following:
This will open up a login form if there is no cached token. If there is a cached token, it will create a new Session and make it active. This will open a session with basic permissions (if the user needs to log in) or open a session with the permissions based on the cached token retrieved. You can then call the re-auth methods to ask for publish permissions. You’ll want to do that in context and typically do not want to call call the auth functions back to back, i.e. log the user in, then immediately ask for publish permissions.