2

我得到了 facebook sdk op 并运行。我尝试获取相册的所有照片。目前我正在使用这个:

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"
            }
         ]
4

1 回答 1

1

when you add objects to your arrayAllPhotos use source instead of id:

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

oh and then when you want to use these images do this:

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

hope it helps

于 2013-01-22T01:29:23.003 回答