php - publish as a page admin using SDK -
i using latest version of facebook's php sdk.i have e page admin. tried post page update using graph api. here code:
//index.php $fb = new facebook\facebook([ 'app_id' => $log_json['app_id'], 'app_secret' => $log_json['app_secret'], 'default_graph_version' => 'v2.4', ]); $helper = $fb->getredirectloginhelper(); $permissions = ['manage_pages', 'pages_show_list', 'publish_pages']; $callback = 'http://localhost:8000/return.php'; $loginurl = $helper->getloginurl($callback, $permissions); echo '<a href="'.$loginurl.'">log in facebook!</a>';
and last part:
//return.php $fb = new facebook\facebook([ 'app_id' => $log_json['app_id'], 'app_secret' => $log_json['app_secret'], 'default_graph_version' => 'v2.4',]); $helper = $fb->getredirectloginhelper(); $client = $fb->getoauth2client(); //for long lived access token try { $accesstoken = $helper->getaccesstoken(); } catch(facebook\exceptions\facebooksdkexception $e) { // there error communicating graph echo $e->getmessage(); exit; } if (isset($accesstoken)) { $longaccesstoken = $client->getlonglivedaccesstoken($accesstoken); db::savelonglivedtoken($longaccesstoken); //save token database $_session['facebook_access_token'] = db::getlonglivedtoken(); //dump($response); $res = $fb->post('<page id>/feed', array('message' => 'hello'), $_session['facebook_access_token']); dump($res); exit; } elseif ($helper->geterror()) { .... exit; }
but when return.php tried call api throws error:
fatal error: uncaught exception 'facebook\exceptions\facebookauthorizationexception' message '(#200) user hasn't authorized application perform action' in.............
Comments
Post a Comment