gpt4 book ai didi

php - Facebook 图谱 API RSS 源

转载 作者:行者123 更新时间:2023-11-29 12:18:15 29 4
gpt4 key购买 nike

我曾经使用 Facebook 的 PHP 在我的应用程序中返回 RSS 提要。现在已弃用。在 Facebook 开发者页面上它说

“页面 RSS Feed 端点 - 位于 https://www.facebook.com/feeds/page.php 现已弃用,并将停止返回 2015 年 6 月 23 日起的数据。开发人员应改为调用 Graph API 的/v2.3/{page_id}/feed 端点。这会返回 JSON 而不是而不是 RSS/XML。”

我对 Facebook Graph API 的工作不多。是否有关于如何像他们在这里提到的那样使用 Graph API 的好教程?

最佳答案

我建立了一个名为 FriendArray 的类,它只有一些字符串属性供我存储链接、图片 url、帖子的第一段和整个帖子的字符串。然后,在我的 TableViewController 中,我使用:

-(void)someMethod {
NSLog(@"App Opened");
if ([FBSDKAccessToken currentAccessToken]) {
[self.loginButton removeFromSuperview];
NSLog(@"Logged In");
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"/v2.3/116178611870507/feed?limit=20" parameters:[NSMutableDictionary dictionaryWithObject:@"id, actions, message, full_picture" forKey:@"fields"]]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
// NSLog(@"fetched user:%@", result);
self.friendObjects = [result objectForKey:@"data"];
self.jobsTemp = [[NSMutableArray alloc] initWithCapacity:self.friendObjects.count];
// NSLog(@"%@", self.friendObjects);
for(NSDictionary *jobsInfo in self.friendObjects) {
NSArray *paragraphs = [[jobsInfo valueForKey:@"message" ] componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

NSMutableArray *testing = jobsInfo[@"actions"];
NSMutableArray *testing2 = [testing valueForKey:@"link"];
FriendArray *jobby = [[FriendArray alloc] init];
jobby.message = [paragraphs objectAtIndex:0];
// jobby.name = jobsInfo[@"additional"];
jobby.picture = jobsInfo[@"full_picture"];
jobby.dateCreated = jobsInfo[@"created_time"];
jobby.allOfIt = jobsInfo[@"message"];
jobby.theLink = [testing2 objectAtIndex:0];

NSLog(@"%@", [testing2 objectAtIndex:0]);

if (jobby.allOfIt == nil) {


jobby.theHtml = [[[[NSString stringWithFormat:@"<html><body><img src=\"%@\">", jobby.picture ] stringByAppendingString:@"\n"] stringByAppendingString:@""] stringByAppendingString:@"</body></html>"];
NSLog(@"Name%@", jobby.theHtml);

[self.jobsTemp addObject:jobby];
}
else {
jobby.theHtml = [[[NSString stringWithFormat:@"<html>"
"<head>"
"<script type=\"text/javascript\" >"
"function display(img){"
"var imgOrigH = document.getElementById('image').offsetHeight;"
"var imgOrigW = document.getElementById('image').offsetWidth;"
"var bodyH = window.innerHeight;"
"var bodyW = window.innerWidth;"
"if((imgOrigW/imgOrigH) > (bodyW/bodyH))"
"{"
"document.getElementById('image').style.width = bodyW + 'px';"
"document.getElementById('image').style.top = (bodyH - document.getElementById('image').offsetHeight)/2 + 'px';"
"}"
"else"
"{"
"document.getElementById('image').style.height = bodyH + 'px';"
"document.getElementById('image').style.marginLeft = (bodyW - document.getElementById('image').offsetWidth)/2 + 'px';"
"}"
"}"
"</script>"
"</head>"
"<body style=\"margin:0;width:100%%;height:100%%;\" >"
"<img id=\"image\" src=\"%@\" onload=\"display()\" /><font size=5><div align=\"center\">", jobby.picture ] stringByAppendingString:jobby.allOfIt] stringByAppendingString:@"</font></div></body></html>"];
NSLog(@"Name%@", jobby.theHtml);

[self.jobsTemp addObject:jobby];
}

}
self.jobsArray = self.jobsTemp;
//NSLog(@"ARRAY%@", self.jobsArray);//set @property (nonatomic, copy) NSArray *jobsArray; in the .h
[self.tableView reloadData];

// NSLog(@"%@", self.theEntries);

}
else {
NSLog(@"%@", error);
UIAlertView *error2 = [[UIAlertView alloc] initWithTitle:@"ERROR" message:[NSString stringWithFormat:@"%@", error ] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[error2 show];
}
}];
} else {
NSLog(@"Not Logged In");
UIAlertView *login = [[UIAlertView alloc] initWithTitle:@"Please Login" message:@"Stronger Marriages now requires a login to Facebook in order to access its latest posts and messages. Thank you!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[login show];
}
//[self refresh];
}

这为我提供了链接、整篇文章、文章的第一段和更大尺寸图像(如果存在)的 URL。从那里开始,只需使用返回的数据设置 cellForRowAtIndexPath 方法即可。

关于php - Facebook 图谱 API RSS 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31444251/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com