如何获得与来自Facebook图形API的iOS特定ID的图像?(how to get an ima

2019-10-20 09:35发布

在我的应用我试图从Facebook页面照​​片/相册获取的具体形象。 我可以得到所有的图像只是一个NSArray很好,但我应该怎么查询我想要的特定图像。

这是我的网址:@“ https://graph.facebook.com/v2.0/albumid/photos ”,这给了我像阵列与它们的源url,但他们是我可以用它来获得无图像ID像我想要的。

任何帮助,将不胜感激。

谢谢,

Answer 1:

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

从这个链接,你可以得到id个人照片,来源和图片。



Answer 2:

你第一次得到URL从它的网址,然后加载到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);
    }];


Answer 3:

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

          }];
     }
 }];


文章来源: how to get an image with specific id from Facebook graph api iOS?