title: Facebook PHP SDK access token issue when retrieve User Profile via the Graph API
body: <p>I have trying to retrieve user profile in my website.
  But after I get the access token, I can't use it. The result it show is</p>
  
  <pre><code>Graph returned an error: Invalid OAuth access token
  </code></pre>
  
  <p>I can get the access token by below code</p>
  
  <p><strong>Login.php</strong>
      
  
  <pre><code>session_start();
  
  require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
  
  $fb = new Facebook\Facebook([
    'app_id' =&gt; 'I have insert correct app id',
    'app_secret' =&gt; 'and app secret',
    'default_graph_version' =&gt; 'v2.0',
    ]);
  
  $helper = $fb-&gt;getRedirectLoginHelper();
  $permissions = ['email'];
  $loginUrl = $helper-&gt;getLoginUrl('http://myweb.com/login-callback.php', $permissions);
  
  echo '&lt;a href="' . htmlspecialchars($loginUrl) . '"&gt;Log in with Facebook!&lt;/a&gt;';
  ?&gt;
  </code></pre>
  
  <p>And below is <strong>login-callback.php</strong></p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  require_once __DIR__ . '/facebook-php-sdk-v4-5.0-dev/src/Facebook/autoload.php';
  
  $fb = new Facebook\Facebook([
    'app_id' =&gt; 'I have insert correct app id',
    'app_secret' =&gt; 'and app secret',
    'default_graph_version' =&gt; 'v2.0',
    ]);
  
    $helper = $fb-&gt;getRedirectLoginHelper();
  
    try {
      $accessToken = $helper-&gt;getAccessToken();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e-&gt;getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
      exit;
    }
  
    if (! isset($accessToken)) {
      if ($helper-&gt;getError()) {
        header('HTTP/1.0 401 Unauthorized');
        echo "Error: " . $helper-&gt;getError() . "\n";
        echo "Error Code: " . $helper-&gt;getErrorCode() . "\n";
        echo "Error Reason: " . $helper-&gt;getErrorReason() . "\n";
        echo "Error Description: " . $helper-&gt;getErrorDescription() . "\n";
      } else {
        header('HTTP/1.0 400 Bad Request');
        echo 'Bad request';
      }
      exit;
    }
  
    $_SESSION['fb_access_token'] = (string) $accessToken;
  
    try {
      $response = $fb-&gt;get('/me?fields=id,name', "'".$_SESSION['fb_access_token']."'");
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e-&gt;getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
      exit;
    }
  
    $user = $response-&gt;getGraphUser();
  
    echo 'Name: ' . $user['name'];
    ?&gt;
  </code></pre>
  
  <p>Am I doing something wrong? Please help. Thanks.</p>