Last active
August 29, 2015 14:01
-
-
Save rkueny/6db5a611c796762221d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
} |
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
what is the contents of vendor/autoload.php ??