Reading a Facebook Page RSS Feed with PHP


SUBMITTED BY: Guest

DATE: May 4, 2013, 2:38 p.m.

FORMAT: PHP

SIZE: 1.7 kB

HITS: 1058

  1. <?php
  2. // Without this "ini_set" Facebook's RSS url is all screwy for reading!
  3. // This is the most essential line, don't forget it.
  4. ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
  5. // This URL is the URL to the Facebook Page's RSS feed.
  6. // Go to the page's profile, and on the left-hand side click "Get Updates vis RSS"
  7. $rssUrl = "http://www.facebook.com/feeds/page.php?id=119425148134433&format=rss20";
  8. $xml = simplexml_load_file($rssUrl); // Load the XML file
  9. // This creates an array called "entry" that puts each <item> in FB's
  10. // XML format into the array
  11. $entry = $xml->channel->item;
  12. // This is just a blank string I create to add to as I loop through our
  13. // FB feed. Feel free to format however you want, or do whatever else
  14. // you want with the data.
  15. $returnMarkup = '';
  16. // Now we'll loop through are array. I just have it going up to 3 items
  17. // for this example.
  18. for ($i = 0; $i < 3; $i++) {
  19. $returnMarkup .= "<h3>".$entry[$i]->title."</h3>"; // Title of the update
  20. $returnMarkup .= "<p>".$entry[$i]->link."</p>"; // Link to the update
  21. $returnMarkup .= "<p>".$entry[$i]->description."</p>"; // Full content
  22. $returnMarkup .= "<p>".$entry[$i]->pubDate."</p>"; // The date published
  23. $returnMarkup .= "<p>".$entry[$i]->author."</p>"; // The author (Page Title)
  24. }
  25. // Finally, we return (or in this case echo) our formatted string with our
  26. // Facebook page feed data in it!
  27. echo $returnMarkup;
  28. ?>

comments powered by Disqus