简体   繁体   中英

News Feed Response parsing in iphone using Facebook Graph Api

I am using Facebook Graph API...for fetching the data of news feed of the facebook profile..

and here is the response that i am getting in the console

    {
    application =         {
        id = 2309869772;
        name = Links;
    };
    "created_time" = "2011-02-10T09:44:27+0000";
    from =         {
        id = 1845195019;
        name = "Paritosh Raval";
    };
    icon = "http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif";
    id = "1845195019_192144087475935";
    likes =         {
        count = 1;
        data =             (
                            {
                id = 1845195019;
                name = "Paritosh Raval";
            }
        );
    };
    link = "http://www.facebook.com/AMDAVAD";
    name = "once you live in AHMEDABAD u cannot live anywhere else in the world..";
    picture = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/203562_115963658443669_4129246_n.jpg";
    properties =         (
                    {
            name = Page;
            text = "21,803 people like this.";
        }
    );
    type = link;
    "updated_time" = "2011-02-10T09:44:27+0000";
},
    {
    application =         {
        id = 2392950137;
        name = Video;
    };
    "created_time" = "2011-02-02T04:18:22+0000";
    description = "must watch and explore :))";
    from =         {
        id = 1845195019;
        name = "Paritosh Raval";
    };
    icon = "http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif";
    id = "1845195019_194836027209359";
    likes =         {
        count = 1;
        data =             (
                            {
                id = 100000701228096;
                name = "Bhargav Jani";
            }
        );
    };
    link = "http://www.facebook.com/video/video.php?v=152586058110610&comments";
    name = "It Happens Only in....";
    "object_id" = 152586058110610;
    picture = "http://vthumb.ak.fbcdn.net/hvthumb-ak-snc4/50893_152586468110569_152586058110610_18299_1832_t.jpg";
    properties =         (
                    {
            name = Length;
            text = "0:54";
        }
    );
    source = "http://video.ak.fbcdn.net/cfs-ak-ash2/70137/56/152586058110610_53804.mp4?oh=481e53b824f6db8e3195fc9c0d07571d&oe=4DAFC300&__gda__=1303364352_7670272db65e93ec75dcaaed16b6d805";
    type = video;
    "updated_time" = "2011-02-02T04:18:22+0000";
}

And I want to show every data in the organized structure in the console. Can anyone help me with this?

it's unclear what you exactly asking but I try to answer.

First of all you need to parse this response in the method - (void)request:(FBRequest *)request didLoad:(id)result of Facebook iOS SDK

result can be a string, a NSArray if you have multiple results and NSDictionary

In you console output we can see NSDictionary with included arrays and dictionaries in it. I have little tutorial about it but it's on russian only and site is down today :( so i just copy one example from my article.

Let say we want to know what facebook user Likes

- (IBAction)getUserInfo:(id)sender {
  [_facebook requestWithGraphPath:@"me/likes" andDelegate:self];
}

if we try this Graph API response in browser or output to console we can see what this request returns. It returns dictionary with one and only key - "data" and corresponded array to this key. This array contents dictionary objects again with keys -
«name»,"category","id","created_time". Dont forget request «user_likes» permission before. So we have parsing method like that:

- (void)request:(FBRequest *)request didLoad:(id)result {
    if ([result isKindOfClass:[NSArray class]]) {
        result = [result objectAtIndex:0];
    }
    if ([result objectForKey:@"owner"]) {
        [self.label setText:@"Photo upload Success"];
    } else if ([result objectForKey:@"data"]){
        NSArray *likes = [result objectForKey:@"data"];
        NSString *text=@"You don't like Steve";
        for (NSDictionary* mylike in likes) {
            NSString *mylikeName = [mylike objectForKey:@"name"];
            if ([mylikeName isEqualToString:@"Steve Jobs"]) {
                text=@"You like Steve";
                break;
            }
        }
        [self.label setText:text];
    }
};

You can parse you result same way and fill your object's variables and then use it to display information in TableView for example. good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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