简体   繁体   中英

Facebook Graph API for iphone

check this Facebook GraphAPI

I am using this Graph API. It is not showing login screen every time,I start this app.And I can see the results on console. I want to know how can I save result of method in NSDictionary to display it in tableView or some label..Method is

-(IBAction)getMeFeedButtonPressed:(id)sender {
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@"me/feed" withGetVars:nil];
NSLog(@"getMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);

}

Thanks in advance

I did this while using your kind-a stuff..

NSString *customString=[NSString stringWithFormat:@"me/feed"];
NSLog(@"here responce is for %@",customString);

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:customString withGetVars:nil];
NSLog(@"getMeFeedButtonPressed:  %@", fb_graph_response.htmlResponse);


//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];   
//  [facebook_response ]
[parser release];

//NSString *feed;
//  NSString *feed2;
NSMutableArray *feed =(NSMutableArray *) [facebook_response objectForKey:@"data"];

//  NSMutableArray *feed1=(NSMutableArray *) [feed valueForKey:@"type"];
NSLog(@"%@",feed);

int index;
NSString* strMessage;


for (index=0; index<[feed count]; index++) {

    //NSLog(@"........%@",[feed objectAtIndex:2]);
    NSString* forTable=[feed objectAtIndex:index];

    NSString *tempString = [forTable valueForKey:@"type"];
    NSLog(@"--------%@",tempString);

    if([tempString isEqualToString:@"status"]){
        NSLog(@"do something with status");
        strMessage=[forTable valueForKey:@"message"];
        NSString* strTime   =[forTable valueForKey:@"created_time"];
        NSLog(@"\n %@ \n %@ ",strMessage,strTime);
        [friendsArray addObject:strMessage];

    }
    else if([tempString isEqualToString:@"link"]){
        NSLog(@"do something with link");
        strMessage=[forTable valueForKey:@"message"];
        NSString* nameStr   =[forTable valueForKey:@"name"];
        NSLog(@"\n %@ \n %@ ",strMessage,strTime);
        [friendsArray addObject:strMessage];
                    [nameArray addObject:nameStr];

    }
    else if([tempString isEqualToString:@"photo"]){
        NSLog(@"do something with photo");
        strMessage=[forTable valueForKey:@"link"];
        NSString* strTime   =[forTable valueForKey:@"created_time"];
        NSLog(@"\n %@ \n %@ ",strMessage,strTime);
        [friendsArray addObject:strMessage];
    }
    else if([tempString isEqualToString:@"video"]){
        NSLog(@"do something with video");
        strMessage=[forTable valueForKey:@"name"];
        NSString* strTime   =[forTable valueForKey:@"created_time"];
        NSLog(@"\n %@ \n %@ ",strMessage,strTime);
        [friendsArray addObject:strMessage];
    }

}       
NSLog(@"%d",[friendsArray count]);
    NSLog(@"%d",[friendsArray count]);
for(int i =0 ; i < [friendsArray count] ; i++)
{
    NSLog(@"\nelement %d is :%@",i,[friendsArray objectAtIndex:i]);
}


FaceBookTable *detailViewController = [[FaceBookTable alloc] initWithNibName:@"FaceBookTable" bundle:nil];
// ...
// Pass the selected object to the new view controller.
detailViewController.dummyArray=friendsArray;
    detailViewController.dummyNameArray=nameArray;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

after doing this you will have all the data in Feed1. Now parse them according to your requirement of what you want to show in your table:)

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