Get Facebook public posts from a page to a php array

facebook-graph-api, php

Solution

You execute an HTTP GET to PAGE_ID/feed

`HTTP GET https://graph.facebook.com/11239244970/feed?access_token=YOUR_ACCESS_TOKEN`

https://developers.facebook.com/docs/reference/api/page/#feed

in PHP it can be as basic as

$data  = file_get_contents("https://graph.facebook.com/573948779291487/feed?access_token=YOUR_ACCESS_TOKEN");
$data = json_decode($data, true);

or you can use the PHP SDK.

$publicFeed = $facebook->api('/573948779291487/feed');

To get only the page's own posts and not the fans who like the page, use the `/posts` endpoint.

Problem

I just need a code sample that collects public posts from a facebook page to a PHP array. I've created an APP so I have the App ID/API Key and App Secret. For example, let's say that I want to get all the stackoverflow public posts from Facebook. I've found out that stackoverflow's facebook page id is '11239244970', but now, how do I get all their public posts? ``` $appKey = '635000000000874'; $appSecret = '567xxxxxxxxxxxxxxxxxxxxxxxxxx3e6'; $fbPage = '11239244970'; $publicFeed = array(); ```

Original source