How to get Facebook Photo Albums for iOS?

I am making the following simple request on Facebook. My goal is to capture the names of all the user's photo albums:

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

Then I get a JSON response from the server:

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";
    },

Etc. The problem is that when I try to analyze the data with:

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

I get it null. I assume this is happening because the NSDictionarydata is being returned does not know which record nameto focus on. How to analyze data to get all album names ?

+5
source share
1 answer

"result" is actually a collection of dictionaries, so iterate over the array and then grab the name from each element of the array.

for (NSDictionary *anAlbum in [result objectForKey:@"data"]) {
    NSLog(@"%@", [anAlbum objectForKey:@"name"]);
}
+3

All Articles