News Feed Response parsing in iphone using Facebook Graph Api

前端 未结 1 1709
有刺的猬
有刺的猬 2020-12-22 09:31

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



        
相关标签:
1条回答
  • 2020-12-22 10:19

    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!

    0 讨论(0)
提交回复
热议问题