Skip to content

Instantly share code, notes, and snippets.

@dubrod
Created June 17, 2011 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubrod/1031684 to your computer and use it in GitHub Desktop.
Save dubrod/1031684 to your computer and use it in GitHub Desktop.
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