-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfb-callback.php
More file actions
57 lines (47 loc) · 1.7 KB
/
fb-callback.php
File metadata and controls
57 lines (47 loc) · 1.7 KB
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
52
53
54
55
56
57
<?php
include_once('fb-config.php');
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (!isset($accessToken)) {
if ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
exit;
}
if(!$accessToken->isLongLived()){
// Exchanges a short-lived access token for a long-lived one
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo "<p>Error getting long-lived access token: " . $e->getMessage() . "</p>\n\n";
exit;
}
}
//$fb->setDefaultAccessToken($accessToken);
# These will fall back to the default access token
$res = $fb->get('/me',$accessToken->getValue());
$fbUser = $res->getDecodedBody();
$resImg = $fb->get('/me/picture?type=large&amp;redirect=false',$accessToken->getValue());
$picture = $resImg->getGraphObject();
$_SESSION['fbUserId'] = $fbUser['id'];
$_SESSION['fbUserName'] = $fbUser['name'];
$_SESSION['fbAccessToken'] = $accessToken->getValue();
header('Location: welcome.php');
exit;
?>