18.2.14

Facebook group posts on own webpage in PHP

A friend needed his FB groups posts embedded on his webpage so here are some snippets that I don't forget :D
  1. At https://developers.facebook.com create a new APP, after creating you get the required ID and SECRET.
  2. From https://github.com/facebook/facebook-php-sdk download the PHP SDK

require_once(WB_PATH."/include/facebook/src/facebook.php"); // Get from https://github.com/facebook/facebook-php-sdk

$APP_ID = 'APPID';
$APP_SECRET = 'APPSECRET';
$GROUP_ID = 'GROUPID';

$config = array(
    'appId' => $APP_ID,
    'secret' => $APP_SECRET,
    'fileUpload' => false,
    'allowSignedRequest' => false,
);

$facebook = new Facebook($config);
extract($facebook->api("/$GROUP_ID/feed?limit=10"));

$posts = '';
foreach ($data as $d) {
    if (!empty($d['message'])) {
        $posts .= '
  • '.date('d.m.Y H:i', strtotime($d['created_time'])).'

    '.$d['message'].'

  • '; } }

    During googling I found http://pastebin.com/LPnzUQSF, but I didn't try.

    No comments:

    Post a Comment