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

痴心易碎 提交于 2019-11-30 00:22:28

问题


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.


回答1:


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 !




回答2:


I know this is old, but I'll bring it up again! I just spent the last three days busting tail and trying to hack and crack the PHP SDK and Graph API, and I've done alright! I posted a full length lab with code and descriptions on my page, and you can view it below and ask me any questions you might have.

Basically, page feed is in a "graph" of info, or a super array. You use the app to connect to the facebook page, and get the feed. Connecting to a page's feed requires no permission from the page, hence why all you need is your APP ID, APP SECRET, and PAGE ID. The SDK automatically generates the APP ACCESS TOKEN for you, so you'r good there.

From then on, it's just about manipulating the graph. I've learned that Facebook feed has different types of posts. some are "photo", "message", "link". Anyways, check out the lab and tell me what you think.

http://www.callmenick.com/labs/displaying-a-custom-facebook-page-feed



来源:https://stackoverflow.com/questions/6444802/facebook-php-sdk-3-0-how-to-get-my-page-wall-posts-at-any-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!