开发者

how to retrieve friends' list using facebook connect with iphone app

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


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];    
}


This is what I did to output a list of friends to the console. I'm still trying to figure out how to send a message to one of their walls though...

 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);


Use this method to call your getFriends method

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜