2012-07-28 82 views
2

我得到了facebook sdk操作并正在运行。我试图获得一张专辑的所有照片。目前我使用的是:Facebook sdk io从相册中获取照片

NSString *S = [[NSString alloc] initWithFormat:@"%s%@%s","https://graph.facebook.com/",albumID, "/photos"]; 
[facebook requestWithGraphPath:S andDelegate:self]; 

我也得到了一个结果,我试图解析,以照片或照片ID的数组。但我尝试了几个小时,然后在网上搜索,但是我无法找到解决方案。我究竟做错了什么?

- (void)request:(FBRequest *)request didLoad:(id)result 


     for (NSDictionary *anAlbum in [result objectForKey:@"data"]) { 
      [arrayAllPhotos addObject:[anAlbum objectForKey:@"id"]]; 

      NSString *url = [[NSString alloc] initWithFormat:@"https://graph.facebook.com/%@/picture",[arrayAllPhotos objectAtIndex:counter]]; 

      UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]; 
     } 
} 

这是我从Facebook回来的JSON。提前致谢!

{ 
    "data": [ 
     { 
     "id": "244119762368747", 
     "from": { 
      "name": "Eindhovens Studenten Corps Intro", 
      "category": "Non-profit organization", 
      "id": "235447296569327" 
     }, 
     "picture": "http://photos-g.ak.fbcdn.net/hphotos-ak-snc7/392553_244119762368747_67274374_s.jpg", 
     "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc7/s720x720/392553_244119762368747_67274374_n.jpg", 
     "height": 480, 
     "width": 720, 
     "images": [ 
      { 
       "height": 1365, 
       "width": 2048, 
       "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc7/s2048x2048/392553_244119762368747_67274374_n.jpg" 
      }, 
      { 
       "height": 640, 
       "width": 960, 
       "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc7/392553_244119762368747_67274374_n.jpg" 
      }, 
      { 
       "height": 480, 
       "width": 720, 
       "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc7/s720x720/392553_244119762368747_67274374_n.jpg" 
      }, 
      { 
       "height": 320, 
       "width": 480, 
       "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc7/s480x480/392553_244119762368747_67274374_n.jpg" 
      }, 
      { 
       "height": 213, 
       "width": 320, 
       "source": "http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc7/s320x320/392553_244119762368747_67274374_n.jpg" 
      }, 
      { 
       "height": 120, 
       "width": 180, 
       "source": "http://photos-g.ak.fbcdn.net/hphotos-ak-snc7/392553_244119762368747_67274374_a.jpg" 
      }, 
      { 
       "height": 86, 
       "width": 130, 
       "source": "http://photos-g.ak.fbcdn.net/hphotos-ak-snc7/392553_244119762368747_67274374_s.jpg" 
      }, 
      { 
       "height": 86, 
       "width": 130, 
       "source": "http://photos-g.ak.fbcdn.net/hphotos-ak-snc7/s75x225/392553_244119762368747_67274374_s.jpg" 
      } 
     ] 
+0

这是完美的。 NSString * graphPath = [[NSString alloc] initWithFormat:@“%@/photos”,albumId]; Facebook * fb = //您的facebookSDK; [fb requestWithGraphPath:graphPath andDelegate:self]; – Muzammil 2013-12-20 09:09:11

回答

1

当你将对象添加到arrayAllPhotos使用source代替id

[arrayAllPhotos addObject:[NSUrl urlWithString:[anAlbum objectForKey:@"source"]]]; 

哦,然后当你想使用这些图片做到这一点:

UIImage *image = [[UIImage imageWithData:[NSData dataWithContentsOfUrl:[arrayAllPhotos objectAtIndex:indexOfObjectYouWant]]]]; 

希望它有助于

相关问题