Requesting additional Facebook permissions

In this recipe, we will learn how to specify additional permissions to be used by our application.

Getting ready

Following on from our previous recipe, we will learn how to implement additional permissions.

How to do it...

To begin, follow the simple steps as outlined in the given order:

  1. Open the AppDelegate.m implementation file from the Project Navigator.
  2. Next, modify the didFinishLaunchingWithOptions: method as shown in the following code snippet:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen 
      mainScreen] bounds]] autorelease];
    
      // Override point for customization after 
      // application launch.
     self.viewController = [[[ViewController alloc] 
     initWithNibName:@"ViewController" bundle:nil] autorelease];
     self.window.rootViewController = self.viewController;
    
     // Do any additional setup after loading the view, 
     // typically from a nib.
     self.facebook = [[Facebook alloc] 
     initWithAppId:@"YOUR_APPID_HERE" andDelegate:self];
    
     // Check and retrieve authorization information
     NSUserDefaults *defaults = [NSUserDefaults
     standardUserDefaults];
     if ([defaults objectForKey:@"FBAccessTokenKey"] &&
         [defaults objectForKey:@"FBExpirationDateKey"]) {
         self.facebook.accessToken = [defaults 
         objectForKey:@"FBAccessTokenKey"];
        self.facebook.expirationDate = [defaults 
        objectForKey:@"FBExpirationDateKey"];
      }
      // Set up the permissions to use for this App
      NSArray *permissions = [[NSArray alloc]
      initWithObjects:
                  @"user_likes",
                  @"user_birthday",
                  @"user_interests",
                  @"read_stream",nil];
    
      // Check to ensure that we have a valid session object
      if (![self.facebook isSessionValid]) {
          [self.facebook authorize:permissions];
      }
    
      [permissions release];
      [self.window makeKeyAndVisible];
      return YES;
    }

How it works...

In this recipe, we begin by declaring an NSArray object variable permission that will be used to store each of our permissions that we want to request. We then pass this variable to our authorize method of the facebook object, before finally releasing the memory allocated by the object.

Note

For more information on the full list of available permissions that are made available to you, refer to the Facebook Permissions reference at the following URL: https://developers.facebook.com/docs/authentication/permissions/

There's more…

When using Facebook integration within your application, you can specify additional permissions to be used by your application. When you launch the application without specifying additional permissions, this will use the default permissions and will only get the ability to read only the user's basic information and this includes certain properties of the User object such as id, name, picture, gender, and their locale. If you want to read additional data or publish data back to Facebook, you will need to request these additional permissions.

These additional permissions fall into the following sections, as shown in the given table:

Requested permissions

Description

Basic information (no permissions)

When a user authorizes your application and you don't specify additional permissions, your application will only have access to the user's basic information. This includes certain properties such as their id, name, gender, locale, and their profile picture.

User and friend permissions

As a part of the authorization process, you can also request for additional access to your user's profile. You can access information such as their birthday, activities, checkins, and education history. The user must, however, authorize this at startup, in order to continue and authorize your application.

Extended permissions

If you are using the Enhanced Authorization Dialog, the extended permissions will be presented to the user. These types of permissions allow you to read your user's friend lists, read the user's mail inbox, access your user's friend requests, and create and modify events on the user's behalf.

Open graph permissions

These types of permissions allow your applications to publish actions to the Open Graph API and enable it to retrieve any actions that have been published by any other application.

Page permissions

These types of permissions allow you to retrieve access_tokens for pages and applications that the user administrates, and is only compatible with the Graph API.

See also

  • The Implementing the Single Sign On (SSO) feature recipe
  • The Using the Graph API to read JSON data recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset