After battling for many days to write a PHP script to access the feed data from selected public Facebook pages, I finally got the below code to work.
I deployed the script on my server and applied a cron to run it every hour or so for almost a month with no problems but yesterday suddenly it stopped working and now spits out the error:
Unsupported get request. Object with ID '483096775077541' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
What has changed, could someone please help?
<?php
$config['App_ID'] = 'xxxxxxxxx';
$config['App_Secret'] = 'ssssssssssssssssssss';
$token_url = "https://graph.facebook.com/oauth/access_token?"
."client_id=".$config['App_ID']
."&client_secret=".$config['App_Secret']
."&grant_type=client_credentials";
$grant = json_decode( file_get_contents($token_url) );
$page_i = 0;
$page_target = 1;
$graph_url = "https://graph.facebook.com/483096775077541/feed?access_token=".$grant->access_token;
while ($page_i < $page_target) :
$feedtext = file_get_contents($graph_url);
$feed = json_decode( str_replace('\n','<br />',$feedtext) );
foreach($feed->data as $data)
{
if( isset($data->message) ){
$lines = explode('<br />', $data->message);
echo '
<p>
<strong>'.$lines[0].'</strong>
<div>'.$data->message.'</div>';
echo '<div>'.$data->updated_time.'</div>
<div>'.$data->id.'</div>
</p>
';
}
}
$graph_url = $feed->paging->next;
$page_i++;
endwhile;