Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Facebook public posts from a page to a php array

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();
like image 610
budiDino Avatar asked Mar 24 '13 20:03

budiDino


People also ask

How do I get Facebook posts on API?

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.

How can I use Facebook API in PHP?

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.

Is the Facebook API free?

The Graph API is free to use, for all applicable use cases.


1 Answers

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.

like image 199
phwd Avatar answered Sep 30 '22 19:09

phwd