7

我正在将Facebook集成到我的iOS应用程序中,并且想知道如何将Facebook好友加载到表格视图中,以便用户可以选择好友邀请到游戏中,类似于如何完成与朋友的话。将Facebook好友加载到UITableView

我知道[facebook requestWithGraphPath:@"me/friends" andDelegate:self]; 要求来自Facebook的朋友,但我无法确定从那里做什么。不知何故,我想获得朋友ID,以便我可以给他们发送消息。 任何信息或建议将不胜感激。 在此先感谢

+0

问题更多搜索后解决。对于任何人搜索,这里是一个答案http://stackoverflow.com/questions/6491838/retrieve-facebook-friends-list –

回答

4
- (void)getFriendsResponse { 
    FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/friends" withGetVars:nil];// me/feed 
//parse our json 
    SBJSON *parser = [[SBJSON alloc] init]; 
    NSDictionary * facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil]; 
    //init array 
     NSMutableArray * feed = (NSMutableArray *) [facebook_response objectForKey:@"data"]; 
     NSMutableArray *recentFriends = [[NSMutableArray alloc] init]; 

     //adding values to array 
     for (NSDictionary *d in feed) { 

      NSLog(@"see Dicitonary :%@",d); 
      facebook = [[Facebook alloc]initWithFacebookDictionary:d ]; 
      [recentFriends addObject:facebook]; 
      NSLog(@"Postsss :->>>%@",[facebook sender]); 

      [facebook release]; 
     } 

     friends = recentFriends; 

     [self.tableView reloadData]; 
    } 

,然后显示在的NSArray TableView中

3

,如果你想获得用户与个人资料照片,朋友一下子你可以试试这个。第一:

- (void) requestFriends:(NSNumber *) fbUserId 
{ 
    NSLog(@"requesting friends"); 

    NSString* fql1 = [NSString stringWithFormat: 
         @"select uid2 from friend where uid1 = %@", fbUserId ]; 
    NSString* fql2 = [NSString stringWithFormat: 
         @"select uid, name, pic_small from user where uid in (select uid2 from #queryID) order by name"]; 
    NSString* fql = [NSString stringWithFormat: 
        @"{\"queryID\":\"%@\",\"queryUser\":\"%@\"}",fql1,fql2]; 

    NSLog(fql); 

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"queries"]; 

    [_facebook requestWithMethodName:@"fql.multiquery" andParams:params andHttpMethod:@"GET" andDelegate:self]; 
} 

然后,当你得到的答案,然后处理:

-(void) processFriends:(id) result 
{ 
    //NSLog(@"processFriends %@", result); 
    NSArray *queryResults = (NSArray*) result; 
    NSMutableDictionary *firstQuery = [queryResults objectAtIndex:0]; 
    NSMutableDictionary *secondQuery = [queryResults objectAtIndex:1]; 

    NSArray *resultSet1 = [firstQuery objectForKey:@"fql_result_set"]; 
    NSString *resultName1 = [firstQuery objectForKey:@"name"]; 

    NSArray *resultSet2 = [secondQuery objectForKey:@"fql_result_set"]; 
    NSString *resultName2 = [secondQuery objectForKey:@"name"]; 

    NSLog(@"%@\n\%@", resultName2, resultSet2); 

} 

基本上resultSet2是,每一个都包含一个朋友条目的数组,在字典中这些键的每个朋友: - UID - 名 - pic_small

因此,你有你所需要的。 希望它有帮助!