Facebook iOS SDK:获取专辑的封面图片

时间:2015-04-17 09:50:56

标签: ios objective-c facebook facebook-graph-api parse-platform

我正在使用Parse包含Facebook SDK,我需要显示给定用户的专辑列表。我可以正确地获取专辑列表:

[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@/albums", self.facebookUserId]
                          completionHandler:^(  FBRequestConnection *connection, id result,  NSError *error )
        {
            // result will contain an array with your user's albums in the "data" key
            NSArray * albumsObjects = [result objectForKey:@"data"];
            NSMutableArray * albums = [NSMutableArray arrayWithCapacity:albumsObjects.count];

            for (NSDictionary * albumObject in albumsObjects)
            {
                //DO STUFF
            }
            self.albums = albums;
            [self.tableView reloadData];
        }];

此时,每张专辑都需要获得封面图片。 相册对象同时包含id字段和cover_photo字段。我已尝试将两者作为图表查询的参数相同结果:resultnil

NSDictionary *params = @{ @"type": @"album"};//, @"access_token": [[PFFacebookUtils session] accessToken]};

[FBRequestConnection startWithGraphPath: [NSString stringWithFormat:@"/%@/picture", album.coverPath]
                             parameters:params
                             HTTPMethod:@"GET"
                      completionHandler:^( FBRequestConnection *connection, id result,  NSError *error ) {

                          NSString * urlString = [result objectForKey:@"url"];
                          NSURL *url = [NSURL URLWithString:urlString];
                          NSURLRequest *request = [NSURLRequest requestWithURL:url];

                          [cell.imageView setImageWithURLRequest:request
                                                placeholderImage:placeholderImage
                                                         success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {

                                                             weakCell.imageView.image = image;
                                                             [weakCell setNeedsLayout];

                                                         } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                                                             NSLog(@"%@",error.debugDescription);
                                                         }];
                      }];

我在appdelegate [PFFacebookUtils initializeFacebook];我在那里管理的会议在所有其他方面都能完美运作。

这些是我在登录时需要的权限

@[@"user_about_me", @"email", @"user_birthday", @"user_location" ,@"user_friends", @"publish_actions", @"user_photos", @"friends_photos"]

想法? 另外在文档中 https://developers.facebook.com/docs/graph-api/reference/v2.3/album/picture 它说要使用album-id,但那么cover_photo id是什么?

1 个答案:

答案 0 :(得分:2)

这有点奇怪但是当我在图API浏览器中尝试/<id>/picture时,它会自动将?redirect=false附加到请求中。与您的情况类似,当我从Objective-C对此边缘进行Graph API调用时,它给了我null。因此,从图API探测器获得提示,我尝试将此参数附加到我的请求,这实际上使其工作。尝试添加它,看它是否有效。所以,在你的情况下:

[NSString stringWithFormat:@"/%@/picture?redirect=false", album.coverPath]

回复看起来像这样:

{
    data =     {
        "is_silhouette" = 0;
        url = "https://fbcdn-sphotos-f-a.akamaihd.net/hphotos...";
    };
}

您可以从此处url抓取data字段,该字段应为您提供封面照片。