7

我正在努力将 Facebook 集成到我的 iOS 应用程序中,并且想知道如何将 Facebook 朋友加载到表格视图中,以便用户可以选择要邀请的朋友加入游戏,类似于 Words With Friends 中的操作方式。

我知道[facebook requestWithGraphPath:@"me/friends" andDelegate:self]; 从 Facebook 请求朋友,但我无法确定从那里做什么。不知何故,我想获取朋友 ID,以便向他们发送消息。任何信息或建议将不胜感激。提前致谢

4

2 回答 2

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

然后在 TableView 中显示 NSArray

于 2011-08-06T07:41:13.403 回答
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 - name - pic_small

因此,您拥有所需的一切。希望能帮助到你!

于 2012-03-04T00:56:59.143 回答