Get User Data

You can get user data by using the Facebook Graph API if the user has given their permission to share their data and your app has the appropriate permissions to receive this data. This topic shows you how to make a single request for data and how to have a batch of requests in a single request.

Before You Begin

You will need to integrate the FBSDKCoreKit framework from the Facebook SDK for iOS into your app. Learn more.

Add the following import statement:

import FBSDKCoreKit

Single Request

To make a single request, use the FBSDKGraphRequest class to encapsulate the components of the request and the FBSDKGraphRequestConnection class to issue the request. Before you make the request, make sure that you have a valid access token.

The following code example demonstrates how to make a single request:

if ([FBSDKAccessToken currentAccessToken]) {
   [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
    startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

      if (!error) {
         NSLog(@"fetched user:%@", result);

Multiple Requests

You can make multiple requests for data from a single request by using the [FBSDKGraphRequestConnection](/docs/reference/iossdk/current/FBSDKCoreKit/classes/fbsdkgraphrequestconnection.html]. By putting all of your requests into a single request, you make minimize the network traffic.

The following code example demonstrates how to make a request with multiple requests for likes from users who have given permission to share that data.

if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"user_likes"]) {
  FBSDKGraphRequest *requestMe = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"me" parameters:nil];
  FBSDKGraphRequest *requestLikes = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"me/likes" parameters:nil];
  FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];
  [connection addRequest:requestMe
           completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
   //TODO: process me information
  [connection addRequest:requestLikes
            completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    //TODO: process like information
  [connection start];

You can also specify batch parameters with the addRequest:completionHandler: overloads, which includes the ability to create a batch with dependent requests.