rodrigobertin
5/2/2015 - 3:35 AM

face Login

face Login

<?php
@session_start();

$config = array(
  'app_id' => '1615488025331762',
  'app_secret' => '53c6cd9d51cfe8e4105517f999e9bd42',
  'url'=>'http://local.dev/mercadobahia.com.ar/www/index.php',
  'scopes' => array('scope' => 'email,read_friendlists,user_online_presence')
);

require 'vendor/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\GraphUser;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;

FacebookSession::setDefaultApplication($config['app_id'], $config['app_secret']);
$helper = new FacebookRedirectLoginHelper($config['url']);

try {
  $session = $helper->getSessionFromRedirect();

  if ($session):
    $_SESSION['facebook'] = $session->getToken();
    header('Location: index.php');
  endif;

  if (isset($_SESSION['facebook'])):
    $session = new FacebookSession($_SESSION['facebook']);

    $request = new FacebookRequest($session, 'GET', '/me');
    $response = $request->execute();
    $graphObjectClass = $response->getGraphObject(GraphUser::className());

    $facebook_user = $graphObjectClass;
  endif;
} catch(FacebookRequestException $ex) {
  // When Facebook returns an error
} catch(\Exception $ex) {
  // When validation fails or other local issues
}

?>