Created
June 17, 2011 15:50
-
-
Save dubrod/1031684 to your computer and use it in GitHub Desktop.
Facebook Feed Trim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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