I am integrating facebook login and publish feed in my application. And for that I am using Android Simple Facebook
I implemented the Login flow, and then I was working on the Publish flow. For that I want to do the following:
When the user clicks on the share to facebook button in my app, I don't want to publish directly but I want to get the publish permission so I can publish later (similar to instagram, where they only get permission at first and then they publish when you add the photo).
For that I have done this:
if (mSimpleFacebook.isLogin()) {
//The user is logged in so we proceed
if (mSimpleFacebook.getGrantedPermissions().contains(
Permission.PUBLISH_ACTION.getValue())) {
hasPermission = true;
} else {
//we don't have permission we request it.
mSimpleFacebook.requestNewPermissions(
SocialUtilities.getFacebookPublishPermissions(), true,
newPermissionListener);
}
}
However even if I am already logged in and have a session I am prompted to login again before getting permission. I have looked in the code of the Simple Facebook library and it appears that he is logging out and then logging in again, and after login he requests the new permission.
I want to ask, why is it done like that? can't we just request the new permission without logging out then in again (similar to instagram) ? Overriding that behavior in the library is impossible as the SessionManager is private and non accessible.
So is there a way to request new permission without logging out and forcing the user to login again, using the library? Or will I have to put it aside and implement everything from scratch using the native Facebook SDK?
Thank you very much for any help or clarifications on this matter
EDIT: For clarification. in the facebook SDK you can request new permissions, and the user will be presented with the new permission screen to accept. This is similar to instagram And I'm ok with that, that's what I want. But I want to know why the Simple Facebook library is forcing a logout before doing so, is there a way to override that or will I have to stop using that library and reimplement everything by only using the native facebook SDK? Thank
If you want publish permission at the beginning use the following code with Facebook LoginButton
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
else use the following permissions to get the login user details
private static final List<String> PERMISSIONS = Arrays.asList("public_profile","user_friends");
Example:(Request any one permission at a time,don't use both)
loginButton.setReadPermissions(PERMISSIONS);
For requesting new permissions use the following
private void requestfor_new_permissions()
{
Session session = Session.getActiveSession();
if (session != null)
{
// Check whether you have already granted these permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions))
{
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, PERMISSIONS);
session.requestNewPublishPermissions(newPermissionsRequest);
return;
}
else
{
//publish your items
}
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}