title: Can't get userdata from Facebook SDK
body: <p>I'm making a voting application in WordPress, where users can make votes on posts.</p>
  
  <p>To vote, users do not need to have an actual user in WordPress, but instead need to login with Facebook. Then the vote is stored in a custom table, containing an ID, post_id and facebook_id.</p>
  
  <p>But I'm having problems retrieving the userdata of the current facebook user.</p>
  
  <p>For some reason it always fails when trying to get the accessToken, which according to the documentation is need to retrieve the userdata. I've also tried to follow the documentation strictly, but it's the same result. The accessToken cannot be retrieved.</p>
  
  <blockquote>
    <p><strong>Here's how to voting flow should work:</strong></p>
    
    <ol>
    <li>A list of posts is shown, each with a voting-button and a vote-counter.</li>
    <li>When a user is clicking the vote button, a Facebook Login Prompt should appear if not already logged in. If already logged in / after
    logging in, an ajax call is sent along with the page-id and
    facebook-id.</li>
    <li>The data is then stored in the custom table and the vote is complete.</li>
    </ol>
  </blockquote>
  
  <p>The storing part is already working, when I'm using a static string as the facebook-id. The problem lies solely in the implementing of Facebook.</p>
  
  <p>I've added the Facebook SDK with composer like this:
  <code>composer require facebook/graph-sdk</code></p>
  
  <blockquote>
    <p>Note: I'm developing in the sage theme from roots.</p>
  </blockquote>
  
  <hr>
  
  <h2>Here's current my code:</h2>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>$(function() {
      $('.vote-btn').on('click', function() {
  
          let page_id = $(this).data('page-id');
  
          FB.getLoginStatus(function(response) {
              if(response.status === 'connected') {
                  makeVote(page_id);
              } else {
                  loginWithFacebook(),
              }
          }
      });
  };
  
  function makeVote(id) {
      $.post('', {id: id}, function() {
          // Success
      }).fail(function() {
          // Fail
      }).always(function() {
          $('.loader').hide();
      });
  }
  
  function logInWithFacebook() {
      FB.login(function(response) {
          if (response.authResponse) {
              alert('You are logged in &amp; cookie set!');
              // Now you can redirect the user or do an AJAX request to
              // a PHP script that grabs the signed request from the cookie.
          } else {
              alert('User cancelled login or did not fully authorize.');
          }
      });
      return false;
  }
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>namespace App\Controllers;
  
  use Sober\Controller\Controller;
  use Facebook\Facebook;
  use Facebook\Exceptions\FacebookResponseException;
  use Facebook\Exceptions\FacebookSDKException;
  
  class TemplateVoting {
  
      private $post_id:
      private $fb_id;
      private $wpdb;
  
      public function __construct() {
          $this-&gt;wpdb = $GLOBALS['wpdb'];
      }
  
      public function __after() {
          if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  
              $this-&gt;post_id = $_POST['id'];
              $this-&gt;addVote();
          }
      }
  
      private function addVote() {
          if( !is_int( $this-&gt;fb_id() ) ) {
              return;
          }
          $this-&gt;wpdb-&gt;insert("wp_post_votings", [
              "post_id" =&gt; $this-&gt;post_id,
              "fb_id"   =&gt; $this-&gt;fb_id(),
          ]);
      }
  
      private function fb_id() {
          try {
              $response = $fb-&gt;get('/me?fields=id', $this-&gt;getToken());
          } catch(Facebook\Exceptions\FacebookResponseException $e) {
              return $e-&gt;getMessage();
          } catch(Facebook\Exceptions\FacebookSDKException $e) {
              return $e-&gt;getMessage();
          }
  
          $user = $response-&gt;getGraphUser();
          return $user['id'];
      }
  
      private function initApi() {
          $facebook = new Facebook([
              'app_id' =&gt; env('FB_APP_ID'),
              'app_secret' =&gt; env('FB_APP_SECRET'),
              'default_graph_version' =&gt; 'v3.3',
          ]);
      }
  
      private function getToken() {
          $fb = $this-&gt;initApi();
  
          $helper = $fb-&gt;getJavaScriptHelper();
  
          try {
              $accessToken = $helper-&gt;getAccessToken();
          } catch(FacebookResponseException $e) {
              return $e-&gt;getMessage();
          } catch(FacebookSDKException $e) {
              return $e-&gt;getMessage();
          }
  
          if (!isset($accessToken)) {
              return '';
          }
  
          return $accessToken-&gt;getValue();
      }
  
  }
  </code></pre>
  
  <p><strong>End of body-tag</strong></p>
  
  <pre><code>(function(d, s, id){
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = '//connect.facebook.net/en_US/sdk.js';
      fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
  
  
  window.fbAsyncInit = function() {
      FB.init({
          appId: 'app_id', // True app_id is inserted in real project
          cookie: true, // This is important, it's not enabled by default
          version: 'v2.10'
      });
  };
  </code></pre>
  
  <p>I haven't worked with the Facebook SDK or the Graph API before so I'm very lost here.</p>
  
  <p>Anyone knows what I'm doing wrong?</p>