Last active
November 18, 2020 17:06
-
-
Save morales2k/11060265 to your computer and use it in GitHub Desktop.
Get Facebook public posts from a page. This requires facebook's php sdk, and a properly registered app.
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 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'); | |
define("APP_SECRET",'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); | |
define("PAGE_ID",'elnuevodia'); | |
$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>"; | |
$i=0; | |
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>'; | |
} | |
$i++; | |
} | |
?> |
My variation on this theme ...
https://gist.github.com/reducedhackers/2613fc9de2c39333d7d9b235938347b6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi
How did you use this code ? possible to have a full setup ?
thanks