0

I wanted to have a Facebook and Google login button on my website and found a website with a project like that: http://www.smarttutorials.net/oauth-login-for-facebook-twitter-and-google-plus-using-php/

The google login seems to be working fine but the facebook one brings me to the facebook page where I have to login but when I click on login it redirects me to a white page with no errors. This is the facebook code that's apparently causing the blank page:

FacebookSession::setDefaultApplication(FB_APP_ID, FB_APP_SECRET);
$helper = new FacebookRedirectLoginHelper(FB_REDIRECT_URI);

if(isset($_GET['type']) && $_GET['type'] == 'facebook' ){

    $fb_url = $helper->getLoginUrl(array('email'));
    header('Location: ' . $fb_url);
}

$session = $helper->getSessionFromRedirect();

if(isset($_SESSION['token'])){
    $session = new FacebookSession($_SESSION['token']);
    try{
        $session->validate(FB_APP_ID, FB_APP_SECRET);
    }catch(FacebookAuthorizationException $e){
        echo $e->getMessage();
    }
}

$data = array();

if(isset($session)){
    $_SESSION['token'] = $session->getToken();
    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graph = $response->getGraphObject(GraphUser::className());

    $data = $graph->asArray();
    $id = $graph->getId();
    $image = "https://graph.facebook.com/".$id."/picture?width=100";
    $data['image'] = $image;
    if($user_obj->fb_login($data)){header('Location: home.php');}
    else{header('Location: index.php');}
}

The code is apparently from like 2 years ago so maybe that's why, but I can't seem to make it work. Does anyone have an idea what could be wrong with the code?

maxgeraci
  • 103
  • 7
  • _“it redirects me to a white page with no errors”_ - regarding that, you start with the duplicate please, and inform yourself how to configure PHP to tell you what actually went wrong in such a case. – CBroe Jun 21 '17 at 11:51
  • And yes, following outdated tutorials might not be the best idea to begin with. As said in response to your other recent question - looks like this is using the PHP SDK v4, which I would strongly recommend against (especially when you are just starting to build this) - use the current one, v5. Basic examples can be found in the official documentation. – CBroe Jun 21 '17 at 11:52

0 Answers0