Retrieve Facebook page status with no authenticating or permissions issues

If you’re just looking to read the ‘Stream’ or ‘Statuses’ of a Facebook fan page (not a normal Profile page) it can be done very easily. Due to all Fan Pages being public (their are 2 settings: published or unpublished), as long as the Fan page is published then you can retrieve any data from it, no authentication, no API, no messing around.

Step 1 – Find the page feed for the Fan Page
The basic URL format of a Facebook fan page feed is:

https://graph.facebook.com/ID of Page/feed

If you can’t find your unique Page ID read this guide.
Test it by opening the link in another browser window. If you get a whole load of data in square and curly brackets (it’s JSON) that contains posts from your fan page then you’re set for Step 2.

*Please note that this URL gets every post from your Wall/Stream limited to about the 50 most recent from what I’ve seen. This includes everything that other people have posted as well in the form of their posts or comments, etc.

Step 2 – Extract the last status from the feed URL data

Here comes the basic PHP code, you need to put in the Page ID for the

$pageID

variable:

$pageID = "ID of Page"
$url = "https://graph.facebook.com/". $pageID ."/feed";
$json = file_get_contents($url);
$jsonData = json_decode($json);

foreach($jsonData->data as $val) {
	if($val->from->id == $pageID) { //find the first matching post/status by a fan page admin
		$message = $val->message;
		echo $message;
		break; //stop looping on most recent status posted by page admin
	}
}

Things to consider

Extracting the data from Facebook directly using a server-side approach should not be used for production as it’s really inefficient as it adds a noticeable pause to page loading times and will break if Facebook is slow in responding. I provided a basic demo to show how easy it can be done, but you should expand on this by storing the data extracted in a database or file on your server via CRON jobs. Another alternative would be to do it client-side with JavaScript, it depends on the frequency the Fan page data you want is expected to change and what you’re doing with it.

  • http://BandonRandon.com BandonRandon

    Is there a reason you are using a foreach and a break instead of a while loop? 

blog comments powered by Disqus