How to create a rss feed for Facebook Group

Today I have created a simple script that allows to generate a rss feed for Facebook Group. I have used the Facebook PHP SDK version 4.0(the last version).

You must first download the Facebook PHP SDK from here: https://developers.facebook.com/docs/php/gettingstarted/4.0.0

Exctract the content and copy it in a folder called facebook.

Next you can use this code to generate a feed RSS for your Facebook Group:

<?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
<?php echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'; ?>
<channel>
<title>Name of your group</title>
<link>https://www.facebook.com/groups/idgroup</link>
<description>Group's description</description>
<language>en</language>
<lastBuildDate><?php echo date("D, d M Y H:i:s O"); ?></lastBuildDate>
<pubDate><?php echo date("D, d M Y H:i:s O"); ?></pubDate>
<ttl>64</ttl>
<?php
define('FACEBOOK_SDK_V4_SRC_DIR', 'facebook/src/Facebook/');
require 'facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\GraphLocation;
FacebookSession::setDefaultApplication('api_id', 'api_secret_key');
$session = new FacebookSession('access-token');
$session = FacebookSession::newAppSession();
$request = new FacebookRequest(
$session,
'GET',
'/idgroup/feed'
);
$response = $request->execute();
$object = $response->getGraphObject();
$as = $object->asArray();
$i = 0;
foreach($as["data"] as $data):
$id = get_object_vars($as["data"][$i]);
$from = get_object_vars($id["from"]);
$name = $from["name"];
$text = $id["message"];
$lin = get_object_vars($id["actions"][0]);
$link = $lin["link"];
echo '<item>';
echo "<link>".$link."</link>";
echo '<title>'.$name."</title>";
echo '<description>'.substr(strip_tags($text),0,139)."...</description>";
echo '<pubDate>'.date("D, d M Y H:i:s O").'</pubDate>';
echo '</item>';
$i++;
endforeach;
?>
</channel>
</rss>

I have spent an hour to write this script. I hope it will be useful for you.









Leave a Comment