I am trying to set up a script to automatically post a message to a Facebook page I am admin of. I have the code below but currently, instead of posting to the page's wall as the page admin, the post is going to the "visitor posts" section of the page from my personal account. Any ideas on how I can resolve this?
require_once('Facebook/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => 'myappid',
'app_secret' => 'myappsecret',
'default_graph_version' => 'v2.5',
]);
$pageID = 'mypageid';
$accessToken = 'myaccesstoken';
try {
$publish = $fb->post('/' . $pageID . '/feed',
array(
'access_token' => $accessToken,
'message' => $status,
'to' => $pageID
)
);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}