如何从Facebook图形API iOS获取具有特定ID的图像?

时间:2014-07-01 02:58:00

标签: ios xcode facebook facebook-graph-api

在我的应用程序中,我试图从Facebook页面照​​片/相册中获取特定图像。我可以在NSArray中获得所有图像,但我应该如何查询我想要的特定图像。

这是我的网址:@“https://graph.facebook.com/v2.0/albumid/photos”,这给了我一个带有源网址的图像数组,但它们没有图片ID,我可以用它来获取我想要的图片。

任何帮助都将不胜感激。

谢谢,

3 个答案:

答案 0 :(得分:2)

我认为你需要这个,http://graph.facebook.com/v2.0/me?fields=albums.fields(photos.fields(id,source,name,picture))

通过此链接,您可以获得id,单张照片的来源和图片。

答案 1 :(得分:0)

首先从中获取网址,然后将网址加载到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);
    }];

答案 2 :(得分:0)

对于那些使用最新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];
              }

          }];
     }
 }];