Getting Facebook session on Wordpress
did you make a test with just the offical FacebookRedirectLoginHelper from official GitHub?I have used the Facebook SDK a couple of times and never had a problem with missing returns.
So I fixed my issue with help from corvuszero's comment.
Here's the code in my ns-facebook.php
file:
use Facebook\FacebookSession;use Facebook\FacebookRequest;use Facebook\FacebookRedirectLoginHelper;class WP_Facebook{ var $helper; var $session; var $permissions; var $loginurl; public function __construct() { // Initialize the SDK FacebookSession::setDefaultApplication('303664476506500', '0197b7f08cc46f051ddb92dfba077484'); $this->permissions = ['public_profile', 'email']; $this->helper = new FacebookRedirectLoginHelper( home_url('facebook-callback') ); try { $this->session = $this->helper->getSessionFromRedirect(); } catch (FacebookRequestException $e) { // handler } catch (Exception $e) { // handler } if(isset($_SESSION['fb_token'])) { $this->session = new FacebookSession( $_SESSION['fb_token'] ); } if($this->session) { $_SESSION['fb_token'] = $this->session->getToken(); } else { $this->loginurl = $this->helper->getLoginUrl($this->permissions); } } /** * Returns the login URL. * * @return string */ public function login_url() { return $this->loginurl; } /** * Returns the current user's info as an array. */ public function get_user() { if($this->session) { /** * Retrieve User’s Profile Information */ // Graph API to request user data $request = new FacebookRequest($this->session, 'GET', '/me'); $response = $request->execute(); // Get response as an array $user = $response->getGraphObject()->asArray(); return $user; } return false; } public function get_session() { return $this->session; }}