views:

596

answers:

2

Hi, I'm using facebook connect for my iphone app. It is able to authenticate the user and also publish a comment on the user's wall. But I'm not sure how to retrieve the user's friends list. A sample code will be highly appreciated.

Thanks in advance,

-Chandni

+1  A: 

In a class that implements the FBRequestDelegate and FBSessionDelegate do this:

-(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];    
}
David Sowsy
Thanks so much!!! I'll try that today.. Also I'm assuming FBConnect does not have any default page to show the Friends list for iPhone the way they have to publish and to login
Chandni
So David who will call the getFriends method
Chandni
A: 

Use this method to call ur getFriends method - (void)request:(FBRequest*)request didLoad:(id)result

Harpreet