title: getAccessToken() method returns null in facebook PHP SDK 5
body: <p>Hi I'm facing a problem which I couldn't find solution on net. I'm trying to log into my website using facebook login. This is my code. getAccessToken() method always returns null. Please Help me to resolve this error. Thank you. Below is my code.</p>
  
  <p>this is my fbConfig.php file </p>
  
  <pre><code>    &lt;?php
      if(!session_id()){
          session_start();
      }
  
      //Include the autoloader provided in the SDK
      require_once 'C:\xampp\htdocs\FBFunApp\php-graph-sdk-5.x\src\Facebook\autoload.php';
  
  
      //Include required libraries
      use Facebook\Facebook;
      use Facebook\Exceptions\FacebookResponseException;
      use Facebook\Exceptions\FacebookSDKException;
  
      /*
       * Configuration and setup Facebook SDK
      */
      $appId         = '560615054394144'; //Facebook App ID
      $appSecret     = 'AAAAAAAAAAAAAAAAAAAA'; //Facebook App Secret
      $redirectURL   = 'http://localhost:8080/FBFunApp/views/login.php'; //Callback URL
      $fbPermissions = array('email');  //Optional permissions
  
  
      $fb = new Facebook(array('app_id' =&gt; $appId,'app_secret' =&gt; $appSecret,'default_graph_version' =&gt; 'v2.10',));
  
      // Get redirect login helper
      $helper = $fb-&gt;getRedirectLoginHelper();
  
      // Try to get access token
      try {  
          if(isset($_SESSION['facebook_access_token'])){ 
              $accessToken = $_SESSION['facebook_access_token'];
          }else{ 
              $accessToken = $helper-&gt;getAccessToken(); 
              var_dump($accessToken); //returns null
          }
      } catch(FacebookResponseException $e) {
          echo 'Graph returned an error: ' . $e-&gt;getMessage();
          exit;
      } catch(FacebookSDKException $e) {
          echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
          exit;
      }catch(Exception $e){
          echo 'Exception: '+$e-&gt;getMessage();
          exit;
      }   
  
  ?&gt;
  </code></pre>
  
  <p>This is login.php file. Config file is used inside this.</p>
  
  <pre><code>&lt;?php 
      //Include FB config file &amp; User class
      require_once '../config/fbConfig.php';
      require_once '../controllers/User.php';
  
      if(isset($accessToken)){
          if(isset($_SESSION['facebook_access_token'])){
              $fb-&gt;setDefaultAccessToken($_SESSION['facebook_access_token']);
          }else{
              //Put short-lived access token in session
              $_SESSION['facebook_access_token'] = (string) $accessToken;
  
              // OAuth 2.0 client handler helps to manage access tokens
              $oAuth2Client = $fb-&gt;getOAuth2Client();
  
              // Exchanges a short-lived access token for a long-lived one
              $longLivedAccessToken = $oAuth2Client-&gt;getLongLivedAccessToken($_SESSION['facebook_access_token']);
              $_SESSION['facebook_access_token'] = (string) $longLivedAccessToken;
  
              // Set default access token to be used in script
              $fb-&gt;setDefaultAccessToken($_SESSION['facebook_access_token']);
          }
  
          // Redirect the user back to the same page if url has "code" parameter in query string
          if(isset($_GET['code'])){ 
              header('Location: ./');                 
          }
  
          // Getting user facebook profile info
          try {
              $profileRequest = $fb-&gt;get('/me?fields=name,first_name,last_name,email,link,gender,locale,cover,picture');
              $fbUserProfile = $profileRequest-&gt;getGraphNode()-&gt;asArray();
              print_r($fbUserProfile);
          } catch(FacebookResponseException $e) { 
              echo 'Graph returned an error: ' . $e-&gt;getMessage();
              session_destroy();
              // Redirect user back to app login page
              header("Location: ./");
              exit;
          } catch(FacebookSDKException $e) {
              echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
              exit;
          }
  
          // Initialize User class
          $user = new User();
  
          // Insert or update user data to the database
          $fbUserData = array(
              'oauth_provider'=&gt; 'facebook',
              'oauth_uid'     =&gt; $fbUserProfile['id'],
              'first_name'    =&gt; $fbUserProfile['first_name'],
              'last_name'     =&gt; $fbUserProfile['last_name'],
              'email'         =&gt; $fbUserProfile['email'],
              'gender'        =&gt; $fbUserProfile['gender'],
              'locale'        =&gt; $fbUserProfile['locale'],
              'cover'         =&gt; $fbUserProfile['cover']['source'],
              'picture'       =&gt; $fbUserProfile['picture']['url'],
              'link'          =&gt; $fbUserProfile['link']
          );
  
          $userData = $user-&gt;checkUser($fbUserData);      
  
  
          // Put user data into session
          $_SESSION['userData'] = $userData;
  
          // Get logout url
          $logoutURL = $helper-&gt;getLogoutUrl($accessToken, $redirectURL.'views/logout.php');
  
          // Render facebook profile data
          if(!empty($userData)){
              $output  = '&lt;h2 style="color:#999999;"&gt;Facebook Profile Details&lt;/h2&gt;';
              $output .= '&lt;div style="position: relative;"&gt;';
              $output .= '&lt;img src="'.$userData['cover'].'" /&gt;';
              $output .= '&lt;img style="position: absolute; top: 90%; left: 25%;" src="'.$userData['picture'].'"/&gt;';
              $output .= '&lt;/div&gt;';
              $output .= '&lt;br/&gt;Facebook ID : '.$userData['oauth_uid'];
              $output .= '&lt;br/&gt;Name : '.$userData['first_name'].' '.$userData['last_name'];
              $output .= '&lt;br/&gt;Email : '.$userData['email'];
              $output .= '&lt;br/&gt;Gender : '.$userData['gender'];
              $output .= '&lt;br/&gt;Locale : '.$userData['locale'];
              $output .= '&lt;br/&gt;Logged in with : Facebook';
              $output .= '&lt;br/&gt;Profile Link : &lt;a href="'.$userData['link'].'" target="_blank"&gt;Click to visit Facebook page&lt;/a&gt;';
              $output .= '&lt;br/&gt;Logout from &lt;a href="'.$logoutURL.'"&gt;Facebook&lt;/a&gt;'; 
          }else{
              $output = '&lt;h3 style="color:red"&gt;Some problem occurred, please try again.&lt;/h3&gt;';
          }       
      }else{
          // Get login url        
          $loginURL = $helper-&gt;getLoginUrl($redirectURL, $fbPermissions); 
  
          // Render facebook login button
          $output = '&lt;a href="'.htmlspecialchars($loginURL).'"&gt;&lt;img src="../images/app/fb-login.png"&gt;&lt;/a&gt;';
      }
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login with Facebook&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;!-- Display login button / Facebook profile information --&gt;
      &lt;div&gt;&lt;?php echo $output; ?&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>