How to get friends list using facebook connect with iphone app

I am using facebook connection for my iphone application. He can authenticate the user, as well as post a comment on the user's wall. But I'm not sure how to get the user's friends list. Sample code would be much appreciated.

Thanks in advance,

-Chandni

0
source share
3 answers

In a class that implements FBRequestDelegate and FBSessionDelegate, do the following:

-(void) getFriends{
        NSString * funcName = @"friends.get";
        [[FBRequest requestWithDelegate:self] call:funcName params:nil];
}

- (void) processFriendsQuery:(id) result{
   friends = [[NSMutableArray alloc] init];
    NSString * element; 
    gDatabase.userIdList = [[[NSMutableArray alloc] initWithCapacity:MAX_FRIENDS_LIST] autorelease];     

 for (element in result){
    Friend * aFriend = [[[Friend alloc] init]autorelease];  
     NSString * uid = [self dictionaryToUID:element];
     aFriend.userId = (NSMutableString *)  uid;
     [gDatabase.userIdList addObject:aFriend.userId];        
 }      

and then call it in

- (void)request:(FBRequest*)request didLoad:(id)result {
  [self processFriendsQuery:result];    
}
+3
source

Use this method to call a method. getFriends

- (void)request:(FBRequest*)request didLoad:(id)result
0
source

, , . , , ...

 AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];


 //Call the request method
 [[delegate facebook] requestWithGraphPath:@"me/friends" andDelegate:self];


// get the array of friends                
NSArray *data = [result objectForKey:@"data"];

// Check that the user has friends
if ([data count] > 0) {

    NSMutableArray *array = [NSMutableArray array];    
         for (int i = 0; i < data.count; i++){
          id object = [data objectAtIndex:i];
          [array addObject:[object objectForKey:@"name"]];
}

NSLog(@"list of friends %@", array);
0
source

All Articles