Facebook sdk io 从相册中获取照片

Posted

技术标签:

【中文标题】Facebook sdk io 从相册中获取照片【英文标题】:Facebook sdk io getting photo's from album 【发布时间】: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]; 【参考方案1】:

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

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

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

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

希望对你有帮助

【讨论】:

以上是关于Facebook sdk io 从相册中获取照片的主要内容,如果未能解决你的问题,请参考以下文章

使用 iOS SDK 将多张照片作为单个帖子上传,例如时间线照片,而不是 Facebook 中的相册

Facebook iOS SDK - 获取用户相册

Facebook iOS SDK - 分享用户照片

使用 Facebook php sdk 访问相册/照片时,“请求此资源需要访问令牌”

Facebook Graph API - 按用户标签获取照片

在 iPhone 应用程序中,如何将照片发布到 Facebook 粉丝页面。在它之前如何喜欢它?使用 facebook-ios-sdk