Posts

Showing posts from January, 2013

How to retrieve posts from Facebook Page using Facebook Graph API and php

Here's a simple php script that will split out the latest 100 posts from a given Facebook Page. Note that you will need to modify the code at lines 1 and 2 by: generating your own access token either using the oAuth dialog or via Facebook Graph API Explorer . specifying the page id of the target Facebook Page Have fun trying it out! :) <? $access_token="&access_token=YOUR_ACCESS_TOKEN_HERE"; $pageid="THE_PAGE_ID"; $graph_query_url="https://graph.facebook.com/" . $pageid . "?fields=posts.limit(100)" . $access_token; $graph_query_result = @file_get_contents($graph_query_url); $graph_query_obj = json_decode($graph_query_result,true); foreach($graph_query_obj[posts][data] as $p) { echo $p[from][name] . "<br/>"; if ($p[story]) echo $p[story] . "<br/>"; if ($p[message]) echo $p[message] . "<br/>"; if ($p[picture]) echo "<img src='" . $p[p