@@ -1,14 +1,14 @@ |
||
| 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, |
|
| 9 | - 'app_secret' => $appSecret, |
|
| 10 | - 'default_graph_version' => 'v3.2', |
|
| 11 | - ]); |
|
| 8 | + 'app_id' => $appId, |
|
| 9 | + 'app_secret' => $appSecret, |
|
| 10 | + 'default_graph_version' => 'v3.2', |
|
| 11 | + ]); |
|
| 12 | 12 | |
| 13 | 13 | $helper = $fb->getRedirectLoginHelper(); |
| 14 | 14 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | //if(isset($_SESSION['fb_access_token'])){ |
| 13 | 13 | // Get access token from session |
| 14 | - // $accessToken = (string) $_SESSION['fb_access_token']; |
|
| 14 | + // $accessToken = (string) $_SESSION['fb_access_token']; |
|
| 15 | 15 | //}else{ |
| 16 | 16 | $graphActLink = "https://graph.facebook.com/oauth/access_token?client_id={$appId}&client_secret={$appSecret}&grant_type=client_credentials"; |
| 17 | 17 | |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | $_SESSION['fb_access_token'] = $accessToken; |
| 25 | 25 | |
| 26 | 26 | if(isset($_GET['album_id']) && isset($_GET['album_name'])){ |
| 27 | - $album_id = $_GET['album_id']; |
|
| 28 | - $album_name = $_GET['album_name']; //isset($_GET['album_name'])?:header('Location: fb-callback.php'); |
|
| 27 | + $album_id = $_GET['album_id']; |
|
| 28 | + $album_name = $_GET['album_name']; //isset($_GET['album_name'])?:header('Location: fb-callback.php'); |
|
| 29 | 29 | |
| 30 | 30 | // Get photos of Facebook page album using Facebook Graph API |
| 31 | 31 | $graphPhoLink = "https://graph.facebook.com/v3.2/{$album_id}/photos?fields=source,images,name&access_token={$accessToken}"; |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | echo '</div> <br />'; |
| 54 | 54 | echo '<div style="text-align:center">'; |
| 55 | 55 | foreach($fbPhotoData as $data){ |
| 56 | - echo '<span class="dot"></span>'; |
|
| 56 | + echo '<span class="dot"></span>'; |
|
| 57 | 57 | } |
| 58 | 58 | echo '</div>'; |
| 59 | 59 | |
@@ -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 | |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if(isset($_GET['album_id']) && isset($_GET['album_name'])){ |
| 120 | - $album_id = $_GET['album_id']; |
|
| 121 | - $album_name = $_GET['album_name']; //isset($_GET['album_name'])?:header('Location: fb-callback.php'); |
|
| 120 | + $album_id = $_GET['album_id']; |
|
| 121 | + $album_name = $_GET['album_name']; //isset($_GET['album_name'])?:header('Location: fb-callback.php'); |
|
| 122 | 122 | |
| 123 | 123 | // Get photos of Facebook page album using Facebook Graph API |
| 124 | 124 | $graphPhoLink = "https://graph.facebook.com/v3.2/{$album_id}/photos?fields=source,images,name&access_token={$accessToken}"; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | echo "<img src='{$imgSource}' alt='' style='width:100%'>"; |
| 145 | 145 | echo "<div class='text'>{$name}</div>"; |
| 146 | 146 | echo "</div>"; |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | ?> |
| 151 | 151 | \ No newline at end of file |