Facebook PHP SDK 3.0 - How to get my page wall posts at any time?

Onema picture Onema · Jun 22, 2011 · Viewed 15.1k times · Source

I have been trying to read the news feed from a page that I have using an app that I'm coding.

Now I have had some issues trying to do this using the PHP SDK 3.0.

I am able to get the page information, but this is something that is publicly available any way.

My question is how do I get (read) the page wall posts? I'm assuming I have to grant permissions to my app to post to page, but how do I do this?

currently this is the code that I have


$appId = 'XXXXXXXXXXXXXXXXXX';
$secret = 'YYYYYYYYYYYYYYYY';
$pageId = 'ZZZZZZZZZZZZZZZZZZ';

$facebook = new Facebook(array(
  'appId'  => $appId,
  'secret' => $secret
));


$pageProfile = $facebook->api($pageId);
$pagePosts   = $facebook->api($pageId . '/posts/');

echo 'My Page profile';
print_r($pageProfile);
echo 'My Page wall';
print_r($userPosts);

Under 'My Page wall' I don't get anything. I don't get any errors either.

Answer

Quentin picture Quentin · Jun 22, 2011

To access the posts of a page, it is /feed and not /post. Then, here is the correct version of your example :

require "facebook.php";
$facebook = new Facebook(array(
    'appId'  => YOUR_APP_ID,
    'secret' => YOUR_APP_SECRET,
));

$pageFeed = $facebook->api(THE_PAGE_ID . '/feed');

Then the array $pageFeed will contain the 25 latest posts and links to navigation :

Array(
    [data] => Array(
        [0] => Array(
            [id] => ...
            [from] => ...
            [to] => ...
            [message] => ...
            [icon] => ...
            [type] => ...
            [application] => ...
            [created_time] => ...
            [updated_time] => ...
        )
        [1] => ...
        [2] => ...
        ...
        [24] => ...
    )
    [paging] => Array(
        [previous] => https://...
        [next] => https://...
    )
)

Hope that helps !