【问题标题】:Facebook sdk io getting photo's from albumFacebook sdk io 从相册中获取照片
【发布时间】:2012-07-28 17:43:22
【问题描述】:

我得到了 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"
            }
         ]

【问题讨论】:

  • 这是完美的。 NSString *graphPath = [[NSString alloc] initWithFormat:@"%@/photos",albumId]; Facebook *fb = //你的 facebookSDK; [fb requestWithGraphPath:graphPath andDelegate:self];

标签: ios xcode facebook sdk photos


【解决方案1】:

当您向arrayAllPhotos 添加对象时,请使用source 而不是id:

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

哦,然后当您想使用这些图像时,请执行以下操作:

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

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多