public function pagesAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $config = array('app_id' => '1553973548253647', 'app_secret' => 'b0ea352b328e6a61b2ec1f07672db859', 'default_graph_version' => 'v2.5', 'persistent_data_handler' => 'session');
     $fb = new Facebook\Facebook($config);
     $helper = $fb->getPageTabHelper();
     try {
         $accessToken = $helper->getAccessToken();
     } catch (Facebook\Exceptions\FacebookResponseException $e) {
         // When Graph returns an error
         echo 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // When validation fails or other local issues
         echo 'Facebook SDK returned an error: ' . $e->getMessage();
         exit;
     }
     if (!isset($accessToken)) {
         echo 'No OAuth data could be obtained from the signed request. User has not authorized your app yet.';
         exit;
     }
     // Logged in
     echo '<h3>Page ID</h3>';
     var_dump($helper->getPageId());
     echo '<h3>User is admin of page</h3>';
     var_dump($helper->isAdmin());
     echo '<h3>Signed Request</h3>';
     var_dump($helper->getSignedRequest());
     echo '<h3>Access Token</h3>';
     var_dump($accessToken->getValue());
 }
<?php

session_start();
require_once __DIR__ . '/src/Facebook/autoload.php';
$fb = new Facebook\Facebook(['app_id' => '184596515230978', 'app_secret' => '21de49c9776c6f3f3607900aa77bd08c', 'default_graph_version' => 'v2.4']);
$helper = $fb->getRedirectLoginHelper();
$permissions = array("manage_pages", "publish_actions", "publish_pages");
$pageHelper = $fb->getPageTabHelper();
if (isset($_SESSION['facebook_access_token'])) {
    $accessToken = $_SESSION['facebook_access_token'];
} else {
    $accessToken = $helper->getAccessToken();
}
if (isset($accessToken)) {
    if (isset($_SESSION['facebook_access_token'])) {
        $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    } else {
        // getting short-lived access token
        $_SESSION['facebook_access_token'] = (string) $accessToken;
        // OAuth 2.0 client handler
        $oAuth2Client = $fb->getOAuth2Client();
        // Exchanges a short-lived access token for a long-lived one
        $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($_SESSION['facebook_access_token']);
        $_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
        // setting default access token to be used in script
        $fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
    }
    $linkData = ['app_id' => '184596515230978', "position" => "1", "custom_name" => "Mi tab page"];
    $pages_request = $fb->get('/me/accounts?fields=name,access_token');
    $pages = $pages_request->getGraphEdge()->asArray();
    foreach ($pages as $page) {