0

我在 facebook 图形 api 上工作。而且我已经获得了使用我的应用程序的用户的 ID。我可以显示用户的 id 和我想要做什么,它在我的 tableview 的每个单元格中显示一个 FBProfilePictureView 给好用户。

  [[FBRequest requestForMe] startWithCompletionHandler:
 ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
     if (!error) {}

     NSString* fql =
     @"SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";

     [FBRequestConnection startWithGraphPath:@"/fql"
                                  parameters:@{ @"q" : fql}
                                  HTTPMethod:@"GET"
                           completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

                               FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
                               [fql.parameters setObject:@"SELECT uid,name,is_app_user FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:@"q"];

                               [fql startWithCompletionHandler:^(FBRequestConnection *connection,
                                                                 id result,
                                                                 NSError *error) {
                                   if (result) {


                                       NSArray *arrayRsult = [result objectForKey:@"data"];

                                       NSMutableArray *ids = (NSMutableArray *) [arrayRsult valueForKey:@"uid"];
                                       NSMutableArray *names = (NSMutableArray *) [arrayRsult valueForKey:@"name"];

                                       recentFriends = [[NSMutableArray alloc] init];
                                       idFriends = [[NSMutableArray alloc] init];










                                       for (NSDictionary *c  in ids)
                                       {
                                           [idFriends addObject:c];



                                       }


                                        arrayLength = [recentFriends count];




                                       NSLog(@"ids are : %@ ",idFriends);

                                       NSLog(@"there are %i", arrayLength);

我已经完成了,首先,使用以下代码在每个单元格中显示我的 facebook 个人资料图片:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

FBProfilePictureView *prof = [[FBProfilePictureView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];

[[FBRequest requestForMe] startWithCompletionHandler:
 ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
     if (!error) {
         prof.profileID = [user objectForKey:@"id"];
     }
 }];

            [cell addSubview:prof];

}

我不将自定义单元格和笔尖用于自定义单元格。我不知道如何为这个表创建一个数组。我试过这段代码 cell.imageView.image = [idFriends objectAtIndex:indexPath.row]; (idFriends 在 .h 文件中声明为 __block NSMutableArray )谢谢你的帮助!

4

2 回答 2

3

是的,您可以在 中显示用户的头像UITableViewCell,您可以使用 Cell 的默认 ImageView。您可以通过以下方式获取用户的个人资料图片Facebook ID..

要获取配置文件的小/拇指图像,请使用

http://graph.facebook.com/<Friends Facebook ID>/picture?type=small

您也可以尝试以下参数type,正常,大,方形

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://graph.facebook.com/517267866/picture?type=small"]];
UIImage *profilePic = [UIImage imageWithData:imageData];

给定的代码将从 URL 中获取图像并将其分配UIImage给您的UIImageView

如果您想了解更多详细信息,请在此处阅读文档

cell.imageView.image = profilePic;
于 2013-05-08T04:21:51.333 回答
0

Actually using "http://graph.facebook.com//picture?type=small" to fetch the profile image of the user or even their friends is slow.

A better and faster way of doing it to add a FBProfilePictureView object to your view and in it's profileID property, assign the user's Facebook id.

For example: FBProfilePictureView *friendsPic;

friendsPic.profileID = @"1379925668972042";

于 2014-12-29T10:39:23.827 回答