Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login.php
- `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
- <?php
- require_once 'Facebook/autoload.php';
- session_start();
- $fb = new Facebook\Facebook([
- 'app_id' => 'id', // Replace {app-id} with your app id
- 'app_secret' => 'secret',
- 'default_graph_version' => 'v3.2',
- ]);
- $helper = $fb->getRedirectLoginHelper();
- $permissions = ['email,manage_pages, pages_show_list, pages_messaging, public_profile']; // Optional permissions
- $loginUrl = $helper->getLoginUrl('https://localhost/fb/fb-callback.php', $permissions);
- echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>';
- ?>
- `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
- `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
- `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
- Facebook-callback.php
- `````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
- <?php
- require_once 'Facebook/autoload.php';
- session_start();
- $accessToken = 'token';
- $fb = new Facebook\Facebook([
- 'app_id' => 'id', // Replace {app-id} with your app id
- 'app_secret' => 'secret',
- 'default_graph_version' => 'v3.2',
- ]);
- $helper = $fb->getRedirectLoginHelper();
- if (isset($_GET['state'])){
- $helper ->getPersistentDataHandler()->set('state', $_GET['state']);
- }
- try {
- // Returns a `FacebookFacebookResponse` object
- $response = $fb->get(
- '/<post-id>/comments/?fields=from,created_time,message&limit=100',
- $accessToken
- );
- } catch(FacebookExceptionsFacebookResponseException $e) {
- echo 'Graph returned an error: ' . $e->getMessage();
- exit;
- } catch(FacebookExceptionsFacebookSDKException $e) {
- echo 'Facebook SDK returned an error: ' . $e->getMessage();
- exit;
- }
- $graphEdge = $response->getGraphEdge();
- echo "<pre>";
- echo $graphEdge;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment