将Facebook好友加载到UITableView中



我正致力于将Facebook整合到我的iOS应用中,我想知道如何将Facebook好友加载到表格视图中,以便用户可以选择邀请好友加入游戏,就像在Words With friends中所做的那样。

我知道[facebook requestWithGraphPath:@"me/friends" andDelegate:self];从Facebook请求好友,但我不知道从那里做什么。不知何故,我想要得到朋友的id,这样我就可以给他们发消息。任何信息或建议将不胜感激。提前感谢

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

然后在TableView中显示NSArray

如果你想一次性获得用户的好友头像,你可以试试这个。第一:

- (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

所以你有你需要的一切。希望能有所帮助!

相关内容

  • 没有找到相关文章

最新更新