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


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

我应该怎么做才能解决这个问题,这是我的代码,我正在使用Facebook图形API来做到这一点 require_once("src/facebook.php");设置正确的路径

    $config = array();
    $config['appId'] = '000000000000000';
    $config['secret'] = '0000000000000000000000';
    $config['fileUpload'] = false; // optional
    // $config['publish_actions'] = true;
    $fb = new Facebook($config);
    $params = array(
      // this is the access token for Fan Page
      "access_token" => "--------------------- my access token --------------------------",
      "message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
      "link" => "http://www.pontikis.net/blog/auto_post_on_facebook_with_php",
      "picture" => "http://i.imgur.com/lHkOsiH.png ",
      "name" => "How to Auto Post on Facebook with PHP",
      "caption" => "www.pontikis.net",
      "description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."
    );
    try {
      // 466400200079875 is Facebook id of Fan page https://www.facebook.com/pontikis.net 
      $ret = $fb->api('/417648154966881/feed', 'POST', $params);
      echo 'Successfully posted to Facebook Fan Page';
    } catch(Exception $e) {
      echo $e->getMessage();
    }

我有一个带有用户请求权限的代码...我希望这有所帮助。您已将旧版本与Facebook api一起使用,我将尽快更新首选项

require 'src/facebook.php';
        $config = array('appId' => '000000', 'secret' => '000000', );
        $facebook = new Facebook($config);
        try
        {
            $user_id = $facebook -> getUser();
            if($user_id){
                $user_profile = $facebook->api('/me','GET');
            }else {
                      $login_Url = $facebook -> getLoginUrl(array('canvas' => 1, 'fbconnect' => 0, 'scope' => 'user_about_me,user_activities,user_status,read_stream,publish_stream,photo_upload,status_update,publish_actions','redirect_uri' => 'https://yoururl.com/'));
                      exit("<script>window.top.location.replace('$login_Url');</script>");
            }
        }catch(exception $e){
            /
            exit("<script>location.reload();</script>");
    }

更新

网址首选项:https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

错误消息表示您没有授予用户publish_actions权限,或者您根本没有授权用户

关于授权,请查看Facebook文档中的此页面:https://developers.facebook.com/docs/php/gettingstarted/4.0.0

请记住,您需要一个"页面访问令牌"来发布"作为页面",这在以下文章中得到了很好的解释:

  • https://developers.facebook.com/docs/facebook-login/access-tokens
  • http://www.devils-heaven.com/facebook-access-tokens/

基本上,您需要使用 publish_actions AND manage_pages 授权用户并使用 API 调用 /me/accounts 以获取用户所有页面的页面令牌。

。然后是"登录审查"。这些权限仅适用于在应用中具有角色的用户(管理员/开发人员/测试人员)。您需要先与他们一起审核,然后才能向公众发布您的应用程序。

当然,您必须自己完成编程部分。不过这并不难:)