简体   繁体   中英

Display profile picture of some facebook friends (with the id) in a tableview

I work on facebook graph api. And I've allready get the id of users which have using my app. I can display the id of users and what I want to do , It's display in each cell of my tableview a FBProfilePictureView for the good user.

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

I 've allready done , to begin , display my facebook profile picture in each cell with this code :

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

}

I don't use custom cell and nib for custom cells. I don't know how to create an array for this table. I've tried this code cell.imageView.image = [idFriends objectAtIndex:indexPath.row]; (idFriends is declared in the .h file as __block NSMutableArray ) Thanks for your help !

yes, you can display profile picture of user in UITableViewCell , you can use default ImageView of Cell. You can get profile picture of user with its Facebook ID as following..

To get Small/Thumb Image of Profile use

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

You can also try following parameters in type , normal, large, square

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

Given code will grab the image from URL and assign that UIImage to your UIImageView

if you want more detail about it please just Read Documentation here

cell.imageView.image = profilePic;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM