适用于iphone的Facebook Graph API

Abh*_*hek 0 iphone facebook facebook-graph-api

检查这个Facebook GraphAPI

我正在使用此Graph API.它没有每次显示登录屏幕,我启动这个应用程序.我可以在控制台上看到结果.我想知道如何在NSDictionary中保存方法的结果,以便在tableView或某些标签中显示它.方法是

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

}

提前致谢

Jea*_*ard 5

我在使用你的那种东西时这样做了..

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];
Run Code Online (Sandbox Code Playgroud)

执行此操作后,您将获得Feed1中的所有数据.现在根据你想要在表中显示的内容来解析它们:)