Haris
Haris

Reputation: 4230

How create Facebook session with extended permission

How to create facebook session with extended permission in facebook sdk 3.0 for android?

Upvotes: 2

Views: 3003

Answers (3)

Shoshi
Shoshi

Reputation: 2254

u have to first login the user. then when u need to extend permission do as: (i have used this for publish permission)

private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
private static final int REAUTH_ACTIVITY_CODE = 100;
// Check for publish permissions    
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
    Session.ReauthorizeRequest reauthRequest = new Session
           .ReauthorizeRequest(this, PERMISSIONS)
           .setRequestCode(REAUTH_ACTIVITY_CODE);
    session.reauthorizeForPublish(reauthRequest);
    return;
}

isSubsetOf():

private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
  for (String string : subset) {
     if (!superset.contains(string)) {
         return false;
     }
  }
  return true;
}

Upvotes: 3

Anup Cowkur
Anup Cowkur

Reputation: 20563

If you use the facebook LoginButton provided by the SDK (version 3.0), it will handle most of the session management for you and you can easily request permissions like this:

 authButton.setReadPermissions(Arrays.asList("user_location", 
                               "user_birthday", "user_likes"));

Refer the docs for a complete tutorial.

Upvotes: 1

Related Questions