Facebook Page Feed Reader in PHP

Facebook Page feed reader is having one issue when you are going to use file_get_contents(); function when you read it may ask you for browser version .

So for this you have to set your ini for use_agent , You have to keep a line code to set this .

To Get the Facebook Page feed you need to get PageID of your FB page you can get that id in url when you clicked on page listed in left side of your Facebook Account .

i.e:   https://www.facebook.com/pages/PHP-Opensources/433805783370445

So now you are ready for your Facebook Page Reader PHP functionality , I am writing the function below for you.

<?php

// Function to get Facebook Feed data

function fetch_facebook_feed($user, $since = 0)
{
$today = getdate();
$current_date=$today[0];

$data= file_get_contents(“https://www.facebook.com/feeds/page.php?format=rss20&id=$user”);

$xml = @simplexml_load_string($data);
$i=1;
foreach ($xml->channel->item as $item)
{
$publ_timestamp=strtotime($item->pubDate);
$diffr=abs($current_date – $publ_timestamp);
$days = floor($diffr/(60*60*24));
$title=$item->title;
$description=$item->description;
$link=$item->link;
$author=$item->author;

echo ‘<div>’;
echo “<h4> $title </h4><br />
<span> Posted $days days ago </span><br />”;
echo “<p> $description </p><br />
<a href=’ $link ‘ >VIEW FULL POST </a><br />”;
echo “<span>Author: $author; </span><br />”;
echo ‘</div>’;
echo ‘<div></div>’;
if($i==$since) return;
$i++;
}
}

// Calling of above function

 

fetch_facebook_feed(‘433805783370445‘, $since = $count);

?>

Hope above function will be use full for you .

If you like or dislike please comment same so i can improve the function or anything as per your requirement .

Show Buttons
Hide Buttons