Get latest facebook post
function get_latest_facebook() {
// include the facebook sdk
require_once('facebook-php-sdk-master/src/facebook.php');
// connect to app
$config = array();
$config['appId'] = '837379822943445';
$config['secret'] = '939ea46d2762cf4e060ad08cbeba25ea';
$config['fileUpload'] = false; // optional
// instantiate
$facebook = new Facebook($config);
// set page id
$pageid = "176346599242138";
// now we can access various parts of the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
// set counter to 0, because we only want to display 10 posts
$i = 0;
foreach ($pagefeed['data'] as $post) {
if ($post['type'] == 'status' || $post['type'] == 'link' || $post['type'] == 'photo') {
// open up an fb-update div
echo "<div class=\"soc_desc\">";
// post the time
// check if post type is a status
if ($post['type'] == 'status') {
if (empty($post['story']) === false) {
$story = strip_tags($post['story']);
echo substr($story, 0, 85);
} elseif (empty($post['message']) === false) {
$message = strip_tags($post['message']);
echo substr($message, 0, 85);
}
}
// check if post type is a link
if ($post['type'] == 'link') {
echo $post['name'];
}
// check if post type is a photo
if ($post['type'] == 'photo') {
if (empty($post['story']) === false) {
$story = strip_tags($post['story']);
echo substr($story, 0, 85);
} elseif (empty($post['message']) === false) {
$message = strip_tags($post['message']);
echo substr($message, 0, 85);
}
}
echo "</div>"; // close fb-update div
$i++; // add 1 to the counter if our condition for $post['type'] is met
}
// break out of the loop if counter has reached 10
if ($i == 2) {
break;
}
} // end the foreach statement
}