Question

I've never used the Facebook SDK 4, and I'm had a look at a lot of answers on here to no success.

I'm trying to use the facebook login part of the api, but everytime i re-direct back from facebook there are's no session stored.. here's the code:

<?php
// I am using autoload just to make sure it was including the requested classes, it makes no difference if i include them separately the outcome is the same.

function __autoload($classname) {
    $filename = "../Facebook/". end(explode("\\",$classname)) .".php";
    include_once($filename);
}

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookOtherException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphSessionInfo;

// start session
session_start();

// init app with app id and secret - 
FacebookSession::setDefaultApplication( '****','****' );

// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper( 'http://dev.mydomain.co.uk/fb/index.php' );


try {
  $session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
  // When Facebook returns an error
} catch(\Exception $ex) {
  // When validation fails or other local issues
}
if ($session) {
  // Logged in
    print('loggedin');
} else {
    print('no session');
    $loginUrl = $helper->getLoginUrl();
    ?>
    <a href="<?=$loginUrl?>">login</a>
    <?php
}

I've replaced the app id and secret, and the redirect uri is correct but ive just replaced the domain here.

It returns back to my login page, just always prints "no session". So it looks like $session = $helper->getSessionFromRedirect(); is not doing what i need it to.

I got this code from the facebook developers site.

Things I've tried:

  • Including the class files separately instead of autoload
  • Moved the whole thing into a seperate directory with out anything else in the index.php file
  • Removed my .htaccess file to make sure it's not something interfering with the GET requests.
  • I've also tried a few different tutorials i.e http://metah.ch/blog/2014/05/facebook-sdk-4-0-0-for-php-a-working-sample-to-get-started/ using their code exactly (but replacing app_id, app_sec, and the url bits) - but i still return no session

I'm at a bit of a loss, so if someone has experience with this it would be helpful

Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top