开发者

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

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 publi开发者_如何学JAVAcly 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.


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 !


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜