Ashutosh
Ashutosh

Reputation: 5742

how to get an image with specific id from Facebook graph api iOS?

In my app i am trying to fetch an specific image from a Facebook page photos/albums. I can get all the images just fine in an NSArray but how should i query the specific images which i want.

This is my url:@"https://graph.facebook.com/v2.0/albumid/photos" and this gives me an Array of images with their source url but their is no image id that i can use to get the image i want.

Any help would be appreciated.

Thanks,

Upvotes: 1

Views: 1255

Answers (3)

Seema Sharma
Seema Sharma

Reputation: 379

For those who are using latest SDK

self.arrayMedia = [[NSMutableArray alloc]init];

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/albums" parameters:@{@"fields": @"id"} tokenString:[[NSUserDefaults standardUserDefaults] objectForKey:@"FACEBOOK_ACCESSTOKEN"] version:nil HTTPMethod:@"GET"]

 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
     NSLog(@"result albums:%@",result);
     NSLog(@"Error %@",error.description);

     for (NSDictionary *dict in result[@"data"]) {

         [[[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"/%@/photos", dict[@"id"]] parameters:@{@"fields": @"id,url,picture"} tokenString:[[NSUserDefaults standardUserDefaults] objectForKey:@"FACEBOOK_ACCESSTOKEN"] version:nil HTTPMethod:@"GET"]

          startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

              for (NSDictionary *dict in  result[@"data"])
              {
                  [self.aryMedia addObject:dict];
              }

          }];
     }
 }];

Upvotes: 0

Shiva Kumar Ganthi
Shiva Kumar Ganthi

Reputation: 426

I think you need this, http://graph.facebook.com/v2.0/me?fields=albums.fields(photos.fields(id,source,name,picture))

From this link you can get id, source and picture of an individual photo.

Upvotes: 2

HelmiB
HelmiB

Reputation: 12333

You first get url from it then load url into UIImageView.

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:[NSString stringWithFormat:@"http://graph.facebook.com/%@/?fields=picture",fbId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NLog(@"JSON %@",responseObject);
        NSDictionary *pic = [responseObject objectForKey:@"picture"];
        NSDictionary *data = [pic objectForKey:@"data"];
        NSString *url = [data objectForKey:@"url"];

        [imageView setImageWithURL:[NSURL URLWithString:url]];


    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {    
        NLog(@"Error: %@", error);
    }];

Upvotes: 0

Related Questions