问题描述
我正在使用Facebook Graph API ...来获取Facebook个人资料的新闻Feed数据。
这里是我收到的回复控制台
{
application = {
id = 2309869772;
name = Links;
};
created_time=2011-02-10T09:44:27 + 0000;
from = {
id = 1845195019;
name =Paritosh Raval;
};
icon =http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif;
id =1845195019_192144087475935;
likes = {
count = 1;
data =(
{
id = 1845195019;
name =Paritosh Raval;
}
);
};
link =http://www.facebook.com/AMDAVAD;
name =一旦你住在AHMEDABAD你不能住在世界其他任何地方。
picture =http://profile.ak.fbcdn.net/hprofile-ak-snc4/203562_115963658443669_4129246_n.jpg;
properties =(
{
name = Page;
text =21,803个人喜欢这样
}
);
type = link;
updated_time=2011-02-10T09:44:27 + 0000;
},
{
application = {
id = 2392950137;
name =视频;
};
created_time=2011-02-02T04:18:22 + 0000;
description =必须观看和浏览:);
from = {
id = 1845195019;
name =Paritosh Raval;
};
icon =http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif;
id =1845195019_194836027209359;
likes = {
count = 1;
data =(
{
id = 100000701228096;
name =Bhargav Jani;
}
);
};
link =http://www.facebook.com/video/video.php?v=152586058110610&comments;
name =它只发生在....;
object_id= 152586058110610;
picture =http://vthumb.ak.fbcdn.net/hvthumb-ak-snc4/50893_152586468110569_152586058110610_18299_1832_t.jpg;
properties =(
{
name = Length;
text =0:54;
}
);
source =http://video.ak.fbcdn.net/cfs-ak-ash2/70137/56/152586058110610_53804.mp4?oh=481e53b824f6db8e3195fc9c0d07571d&oe=4DAFC300&__gda__=1303364352_7670272db65e93ec75dcaaed16b6d805;
type = video;
updated_time=2011-02-02T04:18:22 + 0000;
}
我想显示控制台中有组织结构中的每个数据。任何人都可以帮助我吗?
目前还不清楚你正在问的是什么,但我试图回答。
$ b
首先,您需要在方法
- (void)request中解析此响应(FBRequest *)请求didLoad:(id)
结果可以是一个字符串,一个NSArray如果您有多个结果和NSDictionary
在控制台输出中,我们可以看到包含数组和字典的NSDictionary。
我有一点关于它的教程,但它只在俄语,网站今天下午:(所以我只是从我的文章中复制一个例子。
让我们说想知道什么是Facebook用户喜欢
- (IBAction)getUserInfo:(id)sender {
[_facebook requestWithGraphPath: @me / likesandDelegate:self];
}
如果我们尝试这个图浏览器中的API响应或输出到控制台,我们可以看到这个请求返回,它返回一个唯一的键 - 数据字典和对应的数组到这个键,这个数组内容字典再次用键键 -
«name»,category,id,created_time。不要忘记请求«user_likes»的权限
所以我们有这样的解析方法:
($)$($)$($)$($)$($)$($)$($)$ {code $ b result = [result objectAtIndex:0];
}
if([result objectF orKey:@owner]){
[self.label setText:@照片上传成功];
} else if([result objectForKey:@data]){
NSArray * likes = [result objectForKey:@data];
NSString * text = @你不喜欢史蒂夫;
for(NSDictionary * mylike in likes){
NSString * mylikeName = [mylike objectForKey:@name];
if([mylikeName isEqualToString:@Steve Jobs]){
text = @你喜欢Steve;
break;
}
}
[self.label setText:text];
}
};
您可以以相同的方式解析结果,并填充对象的变量,然后使用它在TableView中显示信息例如。祝你好运!
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
{
application = {
id = 2309869772;
name = Links;
};
"created_time" = "2011-02-10T09:44:27+0000";
from = {
id = 1845195019;
name = "Paritosh Raval";
};
icon = "http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif";
id = "1845195019_192144087475935";
likes = {
count = 1;
data = (
{
id = 1845195019;
name = "Paritosh Raval";
}
);
};
link = "http://www.facebook.com/AMDAVAD";
name = "once you live in AHMEDABAD u cannot live anywhere else in the world..";
picture = "http://profile.ak.fbcdn.net/hprofile-ak-snc4/203562_115963658443669_4129246_n.jpg";
properties = (
{
name = Page;
text = "21,803 people like this.";
}
);
type = link;
"updated_time" = "2011-02-10T09:44:27+0000";
},
{
application = {
id = 2392950137;
name = Video;
};
"created_time" = "2011-02-02T04:18:22+0000";
description = "must watch and explore :))";
from = {
id = 1845195019;
name = "Paritosh Raval";
};
icon = "http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif";
id = "1845195019_194836027209359";
likes = {
count = 1;
data = (
{
id = 100000701228096;
name = "Bhargav Jani";
}
);
};
link = "http://www.facebook.com/video/video.php?v=152586058110610&comments";
name = "It Happens Only in....";
"object_id" = 152586058110610;
picture = "http://vthumb.ak.fbcdn.net/hvthumb-ak-snc4/50893_152586468110569_152586058110610_18299_1832_t.jpg";
properties = (
{
name = Length;
text = "0:54";
}
);
source = "http://video.ak.fbcdn.net/cfs-ak-ash2/70137/56/152586058110610_53804.mp4?oh=481e53b824f6db8e3195fc9c0d07571d&oe=4DAFC300&__gda__=1303364352_7670272db65e93ec75dcaaed16b6d805";
type = video;
"updated_time" = "2011-02-02T04:18:22+0000";
}
And I want to show every data in the organized structure in the console. Can anyone help me with this?
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!
这篇关于新闻Feed在iPhone中使用Facebook Graph Api解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!