简体   繁体   中英

Facebook Graph API RSS Feed

I used to use Facebook's PHP for returning an RSS Feed in my app. That is now deprecated. On the Facebook developer page it says

"Page RSS Feed endpoint - at https://www.facebook.com/feeds/page.php is now deprecated and will stop returning data from June 23, 2015. Developers should call the Graph API's /v2.3/{page_id}/feed endpoint instead. This returns JSON rather than RSS/XML."

I have not worked much with Facebook Graph API. Is there a good tutorial for how I can use the Graph API like what they mention here?

I set up a class called FriendArray that had just some properties of strings for me to store the strings for link, picture url, first paragraph of post, and entire post. Then, in my TableViewController I use:

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

This gives me the Link, entire post, first paragraph of post, and URL to the larger size image (if one exists). From there, it's just a simple matter of setting your cellForRowAtIndexPath methods with the data returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM