priyadharshini
priyadharshini

Reputation: 158

Its possible to get Facebook friends list in app with latest SDK in IOS

I am trying to get friends list from Facebook to my app.Its possible in new SDK.thank you..

Upvotes: 2

Views: 3679

Answers (4)

Kakshil Shah
Kakshil Shah

Reputation: 3796

Swift version:

var fbRequest = FBSDKGraphRequest(graphPath:"/me/friends", parameters: nil);
fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in

    if error == nil {

        println("Friends are : \(result)")

    } else {

        println("Error Getting Friends \(error)");

    }
}

Note: this only gets you the friends who also use the same app!

Upvotes: 2

priyadharshini
priyadharshini

Reputation: 158

thanks to everyone.my working answer is here

      FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
     [login logInWithReadPermissions:@[@"email"]   handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
         {
     if (error)
     {
         // Process error
     }
     else if (result.isCancelled)
     {
         // Handle cancellations
     }
     else
     {
         if ([result.grantedPermissions containsObject:@"email"])
         {
             NSLog(@"result is:%@",result);
                      if ([FBSDKAccessToken currentAccessToken])
                   {
                 NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

                 [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
                  startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                      if (!error)
                      {
                          NSLog(@"resultis:%@",result);
                      }
                      else
                      {
                          NSLog(@"Error %@",error);
                      }
                  }];

             }
             //[login logOut];
         }
     }
 }];

Upvotes: 1

aramusss
aramusss

Reputation: 2401

Yes it is. You need to use Facebook SDK and it's graph API. You can take a look here:

Getting started - Facebook SDK for iOS

Here is an example of code in Objective-C:

// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{friendlist-id}"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Upvotes: 0

Pankaj Gaikar
Pankaj Gaikar

Reputation: 2483

With Facebook SDK 4.0 onwards, you will get your total facebook friends count and the list of facebook friends who are using the same app. Facebook has restricted this usage, you can use "user_friends" permission to retrieve the list but can have only those friends who are using app created by you. So, no full list access to anyone from now.

Upvotes: 3

Related Questions