| @@ -1,41 +1,41 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 |  if(!session_id()) { | 
| 3 | - session_start(); | |
| 3 | + session_start(); | |
| 4 | 4 | } | 
| 5 | 5 | require_once 'appconfig.php'; | 
| 6 | 6 | |
| 7 | 7 | $fb = new Facebook\Facebook([ | 
| 8 | - 'app_id' => $appId, // variable with My Facebook App ID | |
| 9 | - 'app_secret' => $appSecret, | |
| 10 | - 'default_graph_version' => 'v3.2', | |
| 11 | - ]); | |
| 8 | + 'app_id' => $appId, // variable with My Facebook App ID | |
| 9 | + 'app_secret' => $appSecret, | |
| 10 | + 'default_graph_version' => 'v3.2', | |
| 11 | + ]); | |
| 12 | 12 | $helper = $fb->getRedirectLoginHelper(); | 
| 13 | 13 |  if(isset($_GET['state'])){ | 
| 14 | -  $helper->getPersistentDataHandler()->set('state',$_GET['state']); | |
| 14 | +    $helper->getPersistentDataHandler()->set('state',$_GET['state']); | |
| 15 | 15 | } | 
| 16 | 16 |  try { | 
| 17 | - $accessToken = $helper->getAccessToken(); | |
| 17 | + $accessToken = $helper->getAccessToken(); | |
| 18 | 18 |  } catch(Facebook\Exceptions\FacebookResponseException $e) { | 
| 19 | - // When Graph returns an error | |
| 20 | - echo 'Graph returned an error: ' . $e->getMessage(); | |
| 21 | - exit; | |
| 19 | + // When Graph returns an error | |
| 20 | + echo 'Graph returned an error: ' . $e->getMessage(); | |
| 21 | + exit; | |
| 22 | 22 |  } catch(Facebook\Exceptions\FacebookSDKException $e) { | 
| 23 | - // When validation fails or other local issues | |
| 24 | - echo 'Facebook SDK returned an error: ' . $e->getMessage(); | |
| 25 | - exit; | |
| 23 | + // When validation fails or other local issues | |
| 24 | + echo 'Facebook SDK returned an error: ' . $e->getMessage(); | |
| 25 | + exit; | |
| 26 | 26 | } | 
| 27 | 27 |  if (! isset($accessToken)) { | 
| 28 | -  if ($helper->getError()) { | |
| 28 | +    if ($helper->getError()) { | |
| 29 | 29 |      header('HTTP/1.0 401 Unauthorized'); | 
| 30 | 30 | echo "Error: " . $helper->getError() . "\n"; | 
| 31 | 31 | echo "Error Code: " . $helper->getErrorCode() . "\n"; | 
| 32 | 32 | echo "Error Reason: " . $helper->getErrorReason() . "\n"; | 
| 33 | 33 | echo "Error Description: " . $helper->getErrorDescription() . "\n"; | 
| 34 | -  } else { | |
| 34 | +    } else { | |
| 35 | 35 |      header('HTTP/1.0 400 Bad Request'); | 
| 36 | 36 | echo 'Bad request'; | 
| 37 | - } | |
| 38 | - exit; | |
| 37 | + } | |
| 38 | + exit; | |
| 39 | 39 | } | 
| 40 | 40 | // Logged in | 
| 41 | 41 | echo '<h3>Access Token</h3>'; | 
| @@ -52,27 +52,27 @@ discard block | ||
| 52 | 52 |  //$tokenMetadata->validateUserId('123'); | 
| 53 | 53 | $tokenMetadata->validateExpiration(); | 
| 54 | 54 |  if (! $accessToken->isLongLived()) { | 
| 55 | - // Exchanges a short-lived access token for a long-lived one | |
| 56 | -  try { | |
| 55 | + // Exchanges a short-lived access token for a long-lived one | |
| 56 | +    try { | |
| 57 | 57 | $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); | 
| 58 | -  } catch (Facebook\Exceptions\FacebookSDKException $e) { | |
| 58 | +    } catch (Facebook\Exceptions\FacebookSDKException $e) { | |
| 59 | 59 | echo "<p>Error getting long-lived access token: " . $e->getMessage() . "</p>\n\n"; | 
| 60 | 60 | exit; | 
| 61 | - } | |
| 62 | - echo '<h3>Long-lived</h3>'; | |
| 63 | - var_dump($accessToken->getValue()); | |
| 61 | + } | |
| 62 | + echo '<h3>Long-lived</h3>'; | |
| 63 | + var_dump($accessToken->getValue()); | |
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | //$_SESSION['fb_access_token'] = (string) $accessToken; | 
| 67 | 67 |  try { | 
| 68 | - // Returns a `Facebook\FacebookResponse` object | |
| 69 | -  $response = $fb->get('/me?fields=id,name', $accessToken); | |
| 68 | + // Returns a `Facebook\FacebookResponse` object | |
| 69 | +    $response = $fb->get('/me?fields=id,name', $accessToken); | |
| 70 | 70 |  } catch(Facebook\Exceptions\FacebookResponseException $e) { | 
| 71 | - echo 'Graph returned an error: ' . $e->getMessage(); | |
| 72 | - exit; | |
| 71 | + echo 'Graph returned an error: ' . $e->getMessage(); | |
| 72 | + exit; | |
| 73 | 73 |  } catch(Facebook\Exceptions\FacebookSDKException $e) { | 
| 74 | - echo 'Facebook SDK returned an error: ' . $e->getMessage(); | |
| 75 | - exit; | |
| 74 | + echo 'Facebook SDK returned an error: ' . $e->getMessage(); | |
| 75 | + exit; | |
| 76 | 76 | } | 
| 77 | 77 | $user = $response->getGraphUser(); | 
| 78 | 78 | |
| @@ -23,8 +23,8 @@ discard block | ||
| 23 | 23 | $_SESSION['fb_access_token'] = $accessToken; | 
| 24 | 24 | |
| 25 | 25 |  if(isset($_GET['album_id']) && isset($_GET['album_name'])){ | 
| 26 | -  $album_id =  isset($_GET['album_id'])?$_GET['album_id']:header("Location: fb-callback.php"); | |
| 27 | -  $album_name = $_GET['album_name']; //isset($_GET['album_name'])?:header('Location: fb-callback.php'); | |
| 26 | +    $album_id =  isset($_GET['album_id'])?$_GET['album_id']:header("Location: fb-callback.php"); | |
| 27 | +    $album_name = $_GET['album_name']; //isset($_GET['album_name'])?:header('Location: fb-callback.php'); | |
| 28 | 28 | |
| 29 | 29 | // Get photos of Facebook page album using Facebook Graph API | 
| 30 | 30 |  $graphPhoLink = "https://graph.facebook.com/v3.2/{$album_id}/photos?fields=source,images,name&access_token={$accessToken}"; | 
| @@ -55,8 +55,8 @@ discard block | ||
| 55 | 55 | echo '</div>'; | 
| 56 | 56 | echo '<br/>'; | 
| 57 | 57 | echo '<div style="text-align:center">'; | 
| 58 | -  foreach($fbPhotoData as $data){ | |
| 59 | - echo '<span class="dot"></span>'; | |
| 58 | +    foreach($fbPhotoData as $data){ | |
| 59 | + echo '<span class="dot"></span>'; | |
| 60 | 60 | } | 
| 61 | 61 | echo '</div>'; | 
| 62 | 62 | } |