Based on the Facebook Developer Love blog post here, anything from https://graph.facebook.com/[id]/posts will now require a valid access_token to view. Why they chose to implement this on public Facebook Page data we’ll never know.
Anyway, here is a workaround that will get you a valid access_token without the need to log your site visitors in to Facebook first. Useful if you followed my Web Designer tutorial I wrote about using Facebook pages to drive your news on your website and now are getting a load of errors.
So the first thing to do is go to https://www.facebook.com/developers and set up a new Facebook application. Once you have done that, go into the “Web Site” section and fill in your website details…

Facebook Developer screenshot
You will also notice on that page that you have been assigned an Application ID and Application Secret, make a note of these, and do what the name suggests and keep the Application Secret, a secret (hence why mine is blurred above)
Now jump over to your PHP code and add the following in…
$FBid = 'REPLACE_WITH_PAGE_ID_OR_NAME (eg. "terrorfall")';
$app_id = 'REPLACE_WITH_APPLICATION_ID';
$app_secret = "REPLACE_WITH_APPLICATION_SECRET";
Now you can make a call to a Facebook URL which will issue you an access token, do this like so…
$FBid = 'REPLACE_WITH_PAGE_ID_OR_NAME (eg. "terrorfall")';
$app_id = 'REPLACE_WITH_APPLICATION_ID';
$app_secret = "REPLACE_WITH_APPLICATION_SECRET";
$access_token = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
Now you have an access token, you can make the same graph call and get your page data…
$FBid = 'REPLACE_WITH_PAGE_ID_OR_NAME (eg. "terrorfall")';
$app_id = 'REPLACE_WITH_APPLICATION_ID';
$app_secret = "REPLACE_WITH_APPLICATION_SECRET";
$access_token = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
$FBpage = file_get_contents("https://graph.facebook.com/".$FBid."/posts?".$access_token);
$FBdata = json_decode($FBpage);
Now you can create a loop as before and output all your authenticated Facebook data.
Pete


