简体   繁体   English

如何获得iOS的Facebook相册?

[英]How to get Facebook Photo Albums for iOS?

I'm making the following simple request to Facebook. 我正在向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: 然后,我从服务器获得JSON响应,如下所示:

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 . 我得到null I assume this is happening because the NSDictionary that the data is returned in does not know which name entry to concentrate on. 我假设发生了这种情况,因为返回数据的NSDictionary不知道要关注哪个name条目。 How do I parse the data so that I get the names of all the albums? 如何解析数据以便获取所有相册的名称?

"result" is actually an array of dictionaries, so loop through the array and then grab name from each element in the array. “result”实际上是一个字典数组,因此循环遍历数组,然后从数组中的每个元素中获取名称。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM