适用于 iPhone 的 Facebook 图形 API

发布于 2024-11-05 04:31:53 字数 496 浏览 1 评论 0原文

检查这个 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);

}

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2024-11-12 04:31:53

我在使用你的那种东西时做到了这一点。

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];

完成此操作后,你将拥有 Feed1 中的所有数据。现在根据您想要在表格中显示的内容的要求来解析它们:)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文