开发者

How to fetch the posts of the fanpage?

I am able to display my own facebook wall posts on my own website,( just the last 4 posts) but I'd like to display the last x wall posts of a fan page I admin? How do I get the wall posts from my page?

I am a fan of this page bu开发者_StackOverflow社区t how do i use stream_get to get the wall post?


As long as the posts are public you can access it with PAGE_ID/posts and an application access_token

$access_token = '1111111111|2Cha_1-n5'
$graph_url = "https://graph.facebook.com/Boo/posts?access_token=" 
    . $access_token;
$page_posts = json_decode(file_get_contents($graph_url), true);

Or using the PHP SDK and the page access token you can do something like

$facebook = new Facebook(array(
  'appId'  => "YOUR_APP_ID_HERE",
  'secret' => "YOUR_APP_SECRET_HERE",
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
  $user_posts = $facebook->api('me/posts');
}

Where me corresponds to the page

Then you can paginate using the next and previous parameters to get all posts of the page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜