Search code examples
objective-cfacebookios6

Fetch Facebook friend list using SLRequest in iOS 6.0


I integrated Facebook in iOS 6.0 as described in this question:

How to integrate Facebook in iOS 6 using SLRequest?

But I am not able to fetch the Facebook friend list using SLRequest. Can anyone know how to do this? I want to implement "Play with Friends" kind of features in my game.


Solution

  • I figured it how it should work.

    The below code is working fine for me.

     NSArray *accounts = [accountStore
                                   accountsWithAccountType:facebookAccountType];
              ACAccount *facebookAccount = [accounts lastObject];
              NSString *acessToken = [NSString stringWithFormat:@"%@",facebookAccount.credential.oauthToken];
              NSDictionary *parameters = @{@"access_token": acessToken};
              NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];
              SLRequest *feedRequest = [SLRequest
                                        requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodGET
                                        URL:feedURL
                                        parameters:parameters];
              feedRequest.account = facebookAccount;
              [feedRequest performRequestWithHandler:^(NSData *responseData,
                                                       NSHTTPURLResponse *urlResponse, NSError *error)
               {
                   NSLog(@"%@",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
               }];
          }
          else
          {
              // Handle Failure
          }