Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get Facebook public posts from a page. This requires facebook's php sdk, and a properly registered app.
function make_links($text, $class='', $target='_blank'){
return preg_replace('!((http\:\/\/|ftp\:\/\/|https\:\/\/)|www\.)([-a-zA-Zа-яА-Я0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?!ism', '<a class="'.$class.'" href="//$3" target="'.$target.'">$1$3</a>', $text);
define("APP_ID", 'xxxxxxxxxxxxxxxxxxx');
$config = array(
'appId' => APP_ID,
'secret' => APP_SECRET,
$api = new Facebook($config);
$posts = $api->api("/".PAGE_ID."/posts?limit=50");
//echo "<pre>"; print_r($posts); echo "</pre>";
foreach ($posts['data'] as $post){
$time_ar = explode("T",$post['updated_time']);
echo "<h3>{$time_ar[0]}</h3>";
if(isset($post['message']) && $post['message']) echo "<p>".make_links($post['message'])."</p>";
if(isset($post['story']) && $post['story']) echo "<p>".make_links($post['story'])."</p>";
if($i !== count($posts['data'])-1){
echo '<hr>';

This comment has been minimized.

Copy link

jefamorim commented Jun 4, 2017

Hi! Can I choose the a range of date for the shown posts?

Example: I want to show only from Oct 21, 2017 to Nov 21, 2017.

(I am newbie)


This comment has been minimized.

Copy link

NitramKamunyu commented Jul 14, 2017

Kindly Explain....

Have tried a number of this, but have hit the dead end.

( ! ) Fatal error: Class 'Facebook' not found in C:\wamp64\www\Facebook\facebook-2016.php on line 12
--1 | 0.0031 | 246440 | {main}( ) | ...\facebook-2016.php:0

line12: $api = new Facebook($config);


This comment has been minimized.

Copy link

deejay87 commented Jul 25, 2017

How did you use this code ? possible to have a full setup ?


This comment has been minimized.

Copy link

reducedhackers commented Sep 18, 2017

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.