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();
Your app needs user_posts permission from the person who created the post or the person tagged in the post. Then your app can read: Timeline posts from the person who gave you the permission. The posts that other people made on that person Timeline.
The PHP Facebook SDK is very easy to implement and allows access to to facebook graph APIs for developers. a note of it to use in the PHP code. Create new app by clicking Add New App. Enter all the required details like name, email id and click on Create APP ID to get APP ID and APP SECRET to access the Facebook API.
The Graph API is free to use, for all applicable use cases.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With