Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(#200) The user hasn't authorized the application to perform this action facebook php api error?

Tags:

php

facebook

I am using the following code in order to post to facebook page but I get this error:

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

I get the manage_page permission dialog and I click ok and everything's fine there so I don't understand why I cannot post to the facebook page!

this is my code:

<?php
 include_once 'inc/facebook.php';

 $appId = '000000000000000';
 $secret = '00000000000000000000000';
 $returnurl = 'https://mrdomain.com';
 $permissions = 'manage_pages, publish_stream';

 $fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret));

 $fbuser = $fb->getUser();

 if($fbuser){

    if(isset($_POST['msg']) and $_POST['msg']!=''){
        try{
            $message = array(
                'message' => $_POST['msg']
            );
            $posturl = '/'.$_POST['pageid'].'/feed';
            $result = $fb->api($posturl,'POST',$message);
            if($result){
                echo 'Successfully posted to Facebook Wall...';
            }
        }catch(FacebookApiException $e){
            echo $e->getMessage();
        }
    }

    try{
        $qry = 'select page_id, name from page where page_id in (select page_id from page_admin where uid ='.$fbuser.')';
        $pages = $fb->api(array('method' => 'fql.query','query' => $qry));

        if(empty($pages)){
            echo 'The user does not have any pages.';
        }else{
            echo '<form action="" method="post">';
            echo 'Select Page: <select name="pageid">';
            foreach($pages as $page){
                echo '<option value="'.$page['page_id'].'">'.$page['name'].'</option>';
            }
            echo '</select>';
            echo '<br />Message: <textarea name="msg"></textarea>';
            echo '<br /><input type="submit" value="Post to wall" />';
            echo '</form>';
        }

    }catch(FacebookApiException $e){
        echo $e->getMessage();
    }

 }else{
    $fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions));
    echo '<a href="'.$fbloginurl.'">Login with Facebook</a>';
 }

?>

do i need to do anything else before I can post to the facebook page?

any help would be appreciated.

like image 753
user3806613 Avatar asked Jul 09 '14 14:07

user3806613


1 Answers

From the documentation it looks like you're using a depreciated permission, try publish_actions instead of publish_stream.

like image 155
Jamie Kitson Avatar answered Oct 20 '22 18:10

Jamie Kitson