php - Taking a manual RSS feed from a Facebook page - am I missing something? -
i trying take rss feed client's facebook page, rework contents (posts), edit , present resulting data on website. don't want use widget 3rd party , neither want use facebook api's not give me access raw data.
i have taken feeds before , code have provided works nbc, google etc. nothing facebook. url using works fine in browser not in code , hoping here can point no doubt obvious error.
$xml=("<http://www.facebook.com/feeds/page.php?id=xxxxxxxxxxxxxx&format=rss20>") $xmldoc = new domdocument(); $xmldoc->load($xml); //get elements "<channel>" $channel=$xmldoc->getelementsbytagname('channel')->item(0); $channel_title = $channel->getelementsbytagname('title') ->item(0)->childnodes->item(0)->nodevalue; $channel_link = $channel->getelementsbytagname('link') ->item(0)->childnodes->item(0)->nodevalue; $channel_desc = $channel->getelementsbytagname('description') ->item(0)->childnodes->item(0)->nodevalue; //output elements "<channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br>"); echo($channel_desc . "</p>"); //get , output "<item>" elements $x=$xmldoc->getelementsbytagname('item'); ($i=0; $i<=2; $i++) { $item_title=$x->item($i)->getelementsbytagname('title') ->item(0)->childnodes->item(0)->nodevalue; $item_link=$x->item($i)->getelementsbytagname('link') ->item(0)->childnodes->item(0)->nodevalue; $item_desc=$x->item($i)->getelementsbytagname('description') ->item(0)->childnodes->item(0)->nodevalue; echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br>"); echo ($item_desc . "</p>"); }
you use simplexml_load_file
if doing pretty simple, there few differences between , dom, can read more here.
here code example using simplexml_load_file
:
<?php /** * facebook page feed parser */ function fb_parse_feed( $page_id, $no = 5 ) { // need query feed browser. 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'); // facebook page id $page_id = 'xxxxxxxxxxxxxxx'; // url facebook page's rss feed. $rss_url = 'http://www.facebook.com/feeds/page.php?id=' . $page_id . '&format=rss20'; $xml = simplexml_load_file( $rss_url ); $out = ''; $i = 1; foreach( $xml->channel->item $item ){ $out .= '<div class="entry">'; $out .= '<h3 class="title"><a href="' . $item->link . '">' . $item->title . '</a></h3>'; $out .= '<div class="meta">' . $item->pubdate . ' '. $item->author .'</div>'; $out .= '<div class="content">' . $item->description . '</div></div>'; if( $i == $no ) break; $i++; } echo $out; } // print above fb_parse_feed(); ?>
Comments
Post a Comment