简体   繁体   中英

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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM