dr637349 2015-01-29 06:22
浏览 143
已采纳

用户尚未授权应用程序执行此操作(#200)

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>';
    }
?>
  • 写回答

2条回答 默认 最新

  • drpmazn9021 2015-01-29 08:32
    关注

    publish_stream and offline_access are deprecated since years, where do you guys keep copying your code? You need publish_actions (and of course manage_pages in your case) to post on the wall, as you can read in the docs: https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed#publish

    Also, keep in mind that you need to go through a review process with those permissions if you want to make your App public: https://developers.facebook.com/docs/apps/review/login

    About the read_stream permission:

    This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. For example, Android and iOS apps will not be approved for this permission. In addition, Web, Desktop, in-car and TV apps will not be granted this permission.

    Source: https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference-read_stream

    ...meaning, you will not get read_stream approved.

    Edit: You can also use the permission publish_pages now, if you want to publish something "as Page". See the changelog for more information: https://developers.facebook.com/docs/apps/changelog#v2_3_changes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示