Search code examples
phpfacebookfacebook-pagefacebook-access-token

How to update my Facebook page via an application?


I have a site in which users can post comments. I'd like to update my facebook page' status every time a user on my site posts something. Currently I do this posting comments automatically on Twitter, and redirecting tweets on the connected Facebook account. But this solution is dirty. I already created a Facebook app, but I can't find how to update the status of page automatically. Is this possible?

I tried this as simple test:

#!/usr/bin/php
<?php
require("handlers/FBHandler.php");

$pageId = "my_page_id";
$myAccToken = "my_access_token"; // by access token tool

$facebook = get_facebook();  // array with appId and appSecret

$post = array('access_token' => $myAccToken, 'message' => "This is a test!");
try{
    $res = $facebook->api('/'.$pageId.'/feed','POST',$post);
} catch (Exception $e){
echo $e->getMessage();
    die();
}
?>

Obtaining:

    (#200) The user hasn't authorized the application to perform this action;

Before asking more permissions to users I'm wondering whether this is the right way...

Tnaks in advance.


Solution

  • To POST status updates or do anything with Pages you need to have manage_page permission for it. According to your role for the page the Page, you may or may not still be allowed to Post on the Page. You can use Page Access Token, retrieving the same is documented here. The Page Access Token also do not expire. So you might want to use them as per your requirements.