jalone
jalone

Reputation: 2073

Facebook iOS SDK: get album's cover picture

I am using Parse included Facebook SDK and i need to show the list of albums for a given user. I can correttly get the list of albums:

[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];
        }];

At this point for each album i need to get it's cover picture. The album object has both a id field and an cover_photo one. i have tried with both as parameter for the graph query same outcome: result is nil

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);
                                                         }];
                      }];

I have in the appdelegate [PFFacebookUtils initializeFacebook]; and i manage there the session that is working flawlessly in all other palces.

And these are the permissions i require at login

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

Ideas? Also in the documentation https://developers.facebook.com/docs/graph-api/reference/v2.3/album/picture it says to use the album-id, but then what is the cover_photo id for?

Upvotes: 0

Views: 494

Answers (1)

bangdel
bangdel

Reputation: 2553

This is a bit strange but when I tried /<id>/picture in the graph API explorer, it automatically appended ?redirect=false to the request. And similar to your case, when I made a Graph API call to this edge from the Objective-C, it gave me null. So getting a hint from the graph API explorer, I tried appending this param to my request which actually made it work. Try adding it and see if it works. So, in your case:

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

The response looked something like this:

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

You can grab the url field from data here which should give you the cover photo.

Upvotes: 2

Related Questions