Hi I need to post message on facebook fan page
this is my code When I run this code I have following error (#200) The user hasn't authorized the application to perform this action if access_token token problem ? how can i create access_token
<?php
require 'facebook-php-sdk-master//src/facebook.php';
$appId = '1617691071796143';
$secret = 'd84420ccfe2fa7eecac50ca96936bb21';
$returnurl = 'lankabird.com';
$permissions = 'manage_pages, publish_stream, offline_access,read_stream';
$fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret));
$fbuser = $fb->getUser();
if($fbuser){
$page_id = "1596941017191630";
$page_access_token = "";
//$page_access_token = "1617691071796143|d84420ccfe2fa7eecac50ca96936bb21";
$result = $fb->api("/me/accounts");
// loop trough all your pages and find the right one
if( !empty($result['data']) )
{
foreach($result["data"] as $page)
{
if($page["id"] == $page_id)
{
$page_access_token = $page["access_token"];
break;
}
}
}
else
{
echo "AN ERROR OCCURED: could not get the access_token. Please verify the page ID ".$page_id." exists.";
}
$fb->setAccessToken($page_access_token);
// Now try to post on page's wall
try{
$message = array(
'message' => "YOUR MESSAGE",
);
$result = $fb->api('/'.$page_id.'/feed','POST',$message);
if($result)
{
echo 'Successfully posted to Facebook Wall...';
}
}catch(FacebookApiException $e){
echo $e->getMessage();
}
}else{
$fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions));
echo '<a href="'.$fbloginurl.'">Login with Facebook</a>';
}
?>