Skip to content

Instantly share code, notes, and snippets.

@rkueny
Last active August 29, 2015 14:01
Show Gist options
  • Save rkueny/6db5a611c796762221d9 to your computer and use it in GitHub Desktop.
Save rkueny/6db5a611c796762221d9 to your computer and use it in GitHub Desktop.
<?php
// obligatoire
session_start();
require('config/config.inc.php');
require('vendor/autoload.php'); // load des fichiers Facebook
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\CurlHttpClient;
use Facebook\GraphUser;
FacebookSession::setDefaultApplication($config['appid'], $config['secret']);
$helper = new FacebookRedirectLoginHelper('http://sdkv4.local/');
if(isset($_GET['logout'])) {
unset($_SESSION['fb_token']);
}
// enregistrement du token facebook
if(isset($_SESSION) && isset($_SESSION['fb_token'])) {
$session = new FacebookSession($_SESSION['fb_token']);
try {
if(!$session->validate()) $session = null;
} catch (Exception $e) {
$session = null;
}
} else {
try {
$session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
echo $ex->message; // Facebook exception
} catch( Exception $ex ) {
echo $ex->message; // Other exception
}
}
// si connecté
if(isset($session)) {
$_SESSION['fb_token'] = $session->getToken();
$session = new FacebookSession( $session->getToken() );
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
// infos accessibles
var_dump($graphObject);
echo '<a href="' . $helper->getLogoutUrl($session, 'http://sdkv4.local?logout=true') . '">Logout</a>';
} else {
// nouvelles façon de déclarer les "scopes"
echo '<a href="' . $helper->getLoginUrl( array( 'email', 'user_friends' ) ) . '">Login</a>';
}
@pcakhilnadh
Copy link

what is the contents of vendor/autoload.php ??

@rkueny
Copy link
Author

rkueny commented Dec 15, 2014

The content is auto-generated by Composer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment