kjell Reply #1, 1 year ago
Got a headache when I got up this code, for most of you know how FB does
The code works today, but should work with chunks and stylesheet, Is there anyone who feel to fix that?
You need FACEBOOK_ID, you get it if you check your status image (the url) on Facebook and enter it near the bottom twice in the code.
The last number in that line is how many posts are shown (3).
Examples that I mean is:
here can you see my testpage: http://www.modx-verkstan.se/testpage
The code works today, but should work with chunks and stylesheet, Is there anyone who feel to fix that?
You need FACEBOOK_ID, you get it if you check your status image (the url) on Facebook and enter it near the bottom twice in the code.
The last number in that line is how many posts are shown (3).
Examples that I mean is:
<?php
function fetch_fb_feed($url, $maxnumber) {
/* The following line is absolutely necessary to read Facebook feeds. Facebook will not recognize PHP as a browser and therefore won't fetch anything. So we define a browser here */
ini_set('user_agent', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3');
$updates = simplexml_load_file($url); //Load feed with simplexml
$fb_array = array(); //Initialize empty array to store statuses
foreach ( $updates->channel->item as $fb_update ) {
if ($maxnumber == 0) {
break;
} else {
$desc = $fb_update->description;
//Converts UTF-8 into ISO-8859-1 to solve special symbols issues
// $desc = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $desc);
//Get status update time
$pubdate = strtotime($fb_update->pubDate);
$propertime = gmdate('F jS Y, H:i', $pubdate); //Customize this to your liking
//Get link to update
$linkback = $fb_update->link;
//Store values in array
$fb_item = array(
'desc' => $desc,
'date' => $propertime,
'link' => $linkback
);
array_push($fb_array, $fb_item);
$maxnumber--;
}
}
//Return array
return $fb_array;
}
//Run the function with the url and a number as arguments
$myfb_statuses = fetch_fb_feed('http://www.facebook.com/feeds/page.php?id=FACEBOOK_ID&viewer=FACEBOOK_ID&format=rss20',
3);
//Print Facebook status updates
echo '<ul class="fb-updates">';
foreach ($myfb_statuses as $k => $v) {
echo '<li>';
echo '<span class="update">' .$v['desc']. '</span>';
echo '<span class="date">' .$v['date']. '</span>';
echo '<span class="link"><a target="_blank" href=http://www.facebook.com'
.$v['link']. '>Link to status update</a></span>';
echo '</li>';
}
echo '</ul>';
?>here can you see my testpage: http://www.modx-verkstan.se/testpage