Passed
Push — master ( e9b8fa...70ae29 )
by Kishan
02:22
created

fb-callback.php (1 issue)

Severity
1
<?php
2
3
/** 
4
 * Copyright 2018 Social Manager.
5
 * 
6
 * PHP version 7.2.8
7
 *
8
 * @category Album_Manager
9
 * @package  Facebook
10
 * @author   Kishan Jasani <[email protected]>
11
 * @license  https://rtfbchallenge.000webhostapp.com/privacy_policy/privacy_policy.php 
12
 * @link     ""
13
 * 
14
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
15
 * use, copy, modify, and distribute this software in source code or binary
16
 * form for use in connection with the web services and APIs provided by
17
 * Kishan Jasani.
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
20
 */
21
22
ini_set('max_execution_time', 999999);
23
require_once "config.php";
24
if (isset($_SESSION['accessToken'])) {
25
    $accessToken = $_SESSION['accessToken'];
26
} else {
27
    try {
28
        $accessToken = $helper->getAccessToken();
29
        if (!isset($accessToken)) {
30
            header('Location: https://localhost:8443/SociaManager/login.php');
31
            exit();
32
        }
33
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
34
        // When Graph returns an error
35
        echo 'Graph returned an error: ' . $e->getMessage();
36
        exit;
37
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
38
        // When validation fails or other local issues
39
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
40
        exit;
41
    }
42
43
    // The OAuth 2.0 client handler helps us manage access tokens
44
    $oAuth2Client = $fb->getOAuth2Client();
45
46
    // Get the access token metadata from /debug_token
47
    $tokenMetadata = $oAuth2Client->debugToken($accessToken);
48
49
    // Validation (these will throw FacebookSDKException's when they fail)
50
    $tokenMetadata->validateAppId('XXXXXXXXXXXX'); // Replace {app-id} with your app id
51
    // If you know the user ID this access token belongs to, you can validate it here
52
    $tokenMetadata->validateExpiration();
53
54
    if (! $accessToken->isLongLived()) {
55
        // Exchanges a short-lived access token for a long-lived one
56
        try {
57
            $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
58
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
59
            echo "<p>Error getting long-lived access token: </p>\n\n";
60
            exit;
61
        }
62
    }
63
}
64
65
$_SESSION['accessToken'] = (string) $accessToken;
66
67
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...