-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb-callback.php
33 lines (29 loc) · 981 Bytes
/
fb-callback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
require_once "config.php";
if (!isset($_SESSION['email']) && empty($_SESSION['email'])) {
// code...
try {
$accessToken = $helper->getAccessToken();
} catch (\Facebook\Exceptions\FacebookResponseException $e) {
echo "Response Exception: " . $e->getMessage();
exit();
} catch (\Facebook\Exceptions\FacebookSDKException $e) {
echo "SDK Exception: " . $e->getMessage();
exit();
}
if (!$accessToken) {
header('Location: login.php');
exit();
}
$oAuth2Client = $FB->getOAuth2Client();
if (!$accessToken->isLongLived())
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
$response = $FB->get("/me?fields=id, first_name, last_name, email, picture.type(large)", $accessToken);
$userData = $response->getGraphNode()->asArray();
var_dump($userData);
$_SESSION['userData'] = $userData;
$_SESSION['access_token'] = (string)$accessToken;
}
header('location: ./login.php');
exit();
?>