PHP code example of sohaibilyas / facebook-php-sdk
1. Go to this page and download the library: Download sohaibilyas/facebook-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sohaibilyas / facebook-php-sdk example snippets
session_start();
okPhpSdk\Facebook;
$facebook = new Facebook([
'app_id' => 'app-id-here',
'app_secret' => 'app-secret-here',
'redirect_url' => 'https://sohaibilyas.com'
]);
$facebook->handleRedirect(function($user) {
// 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($_SESSION['access_token'])) {
// setting default access token for all requests
$facebook->setAccessToken($_SESSION['access_token']);
// default response type e.g. object, json, array
$facebook->setResponseType('json');
// getting facebook user information
print_r($facebook->getAdAccounts());
} else {
echo $facebook->getLoginUrl(['email', 'ads_management', 'business_management', 'ads_read']);exit;
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.