Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sohaibilyas committed Jul 30, 2022
1 parent b14c839 commit b1ae46e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ composer require sohaibilyas/facebook-php-sdk

```php
<?php
session_start();

require './vendor/autoload.php';

Expand All @@ -26,20 +27,20 @@ $facebook = new Facebook([
]);

$facebook->handleRedirect(function($user) {
// save access token in database
setcookie('access_token', $user->access_token);
// save access token to use it later e.g. session, database
$_SESSION['access_token'] = $user->access_token;
});

// checking if access token is saved otherwise show login with facebook url
if (isset($_COOKIE['access_token'])) {
if (isset($_SESSION['access_token'])) {
// setting default access token for all requests
$facebook->setAccessToken($_COOKIE['access_token']);
$facebook->setAccessToken($_SESSION['access_token']);

// default response type e.g. object, json, array
$facebook->setResponseType('json');

// getting facebook user information
print_r($facebook->getUser());
print_r($facebook->getAdAccounts());
} else {
echo $facebook->getLoginUrl(['email', 'ads_management', 'business_management', 'ads_read']);exit;
}
Expand Down

0 comments on commit b1ae46e

Please sign in to comment.