Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Facebook Feed Trim
<?php
function facebook_feed() {
$token = "XXXXXX";
$fb_id = "XXXXXX"; // the number in your Facebook URL
$json = json_decode(file_get_contents("https://graph.facebook.com/$fb_id/feed?access_token=$token"), true);
// only grab 1st
if(isset($json["data"][0])) {
$json = $json["data"][0];
}
//get some params from feed
$name = $json["from"]["name"];
$id = $json["from"]["id"];
$message = $json["message"];
$output = "";
$output .= "<a href=\"http://www.facebook.com/#!/profile.php?id=" . $id . "\">" . $name . "</a><br/>";
$output .= "Said: " . $message . "";
//echo "<pre>";print_r($json);echo "</pre>"; // for testing purposes to see the entire feed
$total_words = 20;
print @implode(" ", array_slice(explode(" ", $output), 0, $total_words)) . "<a href=\"http://www.facebook.com/#!/profile.php?id=" . $id . "\">[...]</a>";
}
if (function_exists('facebook_feed')) facebook_feed();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.