从页面获取Facebook公开帖子到php数组

bud*_*ino 7 php facebook-graph-api

我只需要一个代码示例,从facebook页面收集公共帖子到PHP数组.

我创建了一个APP,所以我有App ID/API Key和App Secret.

例如,假设我想从Facebook获取所有stackoverflow公共帖子.我发现stackoverflow的facebook页面ID是'11239244970',但现在,我如何获得所有公开帖子?

$appKey = '635000000000874';
$appSecret = '567xxxxxxxxxxxxxxxxxxxxxxxxxx3e6';
$fbPage = '11239244970';
$publicFeed = array();
Run Code Online (Sandbox Code Playgroud)

phw*_*hwd 10

您执行HTTP GET到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

在PHP中它可以像基本一样

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

或者您可以使用PHP SDK.

$publicFeed = $facebook->api('/573948779291487/feed');
Run Code Online (Sandbox Code Playgroud)

要仅获取页面自己的帖子而不是喜欢该页面的粉丝,请使用/posts端点.

  • 使用的ID - 11239244970,是页面ID.如果我们知道页面网址,请告诉我如何获得? (4认同)
  • @budidino用`/ posts`替换`/ feed` (2认同)