-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb-callback.php
51 lines (42 loc) · 1.38 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// Get configuration file
require_once "config.php";
// Check if access token is set or not
if(isset($_SESSION['accesToken']))
{
header('Location: home.php');
exit();
}
try{
//If get access token
$accestoken = $helper->getAccessToken();
}
catch(\Facebook\Exception\FacebookResponceException $e){
echo "Responce Exception : ".$e->getMessage();
exit();
}
catch(\Facebook\Exception\FacebookSDKException $e){
echo "SDK Exception : ".$e->getMessage();
exit();
}
if(!$accestoken){
// If we can't generate access token redirect to Login
header('Location : login.php');
exit();
}
$oAuth2Client = $FB->getOAuth2Client();
if(!$accestoken->isLongLived())
$accestoken = $oAuth2Client->getLongLivedAccessToken($accestoken);
// $responce = $FB->get('me?fields=id,name,email,picture.type(large)',$accestoken);
$responce = $FB->get('me?fields=name,email,picture.type(large),albums{id,name,photos{source}}',$accestoken);
$userData = $responce->getGraphNode()->asArray();
// echo "<pre>";
$data=json_encode($userData);
// echo $data;
// var_dump($userData);
$_SESSION['josnData']=$data;
$_SESSION['userData'] = $userData;
$_SESSION['accesToken'] = (string)$accestoken;
header('Location: home.php');
exit();
?>