Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Facebook Photo Albums for iOS?

I'm making the following simple request to Facebook. My goal is to grab the names of all a user's photo albums:

[[AppDelegate sharedDelegate].facebook requestWithGraphPath:@"me/albums" andDelegate:[AppDelegate sharedDelegate]];

Then, I get a JSON response from the server like such:

data =     (
            {
        "can_upload" = 1;
        count = 4;
        "cover_photo" = 321491374598618;
        "created_time" = "2012-06-04T21:46:23+0000";
        from =             {
            id = 100002132746588;
            name = "Owner....";
        };
        id = 321491371265285;
        link = "http://www.facebook.com/album.php?fbid=321491371265285&id=100002132746588&aid=73680";
        name = "Photos";
        privacy = custom;
        type = normal;
        "updated_time" = "2012-06-04T22:08:39+0000";
    },
            {
        "can_upload" = 0;
        count = 1;
        "cover_photo" = 318401854907570;
        "created_time" = "2012-05-31T00:00:35+0000";
        description = "Which Friend Stalks You the Most?";
        from =             {
            id = 100002132746588;
            name = "Owner....";
        };
        id = 318401848240904;
        link = "http://www.facebook.com/album.php?fbid=318401848240904&id=100002132746588&aid=73163";
        name = "Which Friend Stalks You the Most?";
        privacy = friends;
        type = normal;
        "updated_time" = "2012-05-31T00:00:36+0000";
    },

And so on. Problem is, when I try to parse the data with:

NSLog(@"%@", [result objectForKey:@"name"]);

I get null. I assume this is happening because the NSDictionary that the data is returned in does not know which name entry to concentrate on. How do I parse the data so that I get the names of all the albums?

like image 272
The Kraken Avatar asked Oct 22 '22 20:10

The Kraken


1 Answers

"result" is actually an array of dictionaries, so loop through the array and then grab name from each element in the array.

for (NSDictionary *anAlbum in [result objectForKey:@"data"]) {
    NSLog(@"%@", [anAlbum objectForKey:@"name"]);
}
like image 80
Andy Obusek Avatar answered Nov 01 '22 10:11

Andy Obusek