Abhishek
Abhishek

Reputation: 303

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

Upvotes: 0

Views: 1215

Answers (1)

Jean-Luc Godard
Jean-Luc Godard

Reputation: 1883

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 :)

Upvotes: 5

Related Questions