PHP code example of lzakrzewski / facebook-authentication-adapter
1. Go to this page and download the library: Download lzakrzewski/facebook-authentication-adapter 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/ */
lzakrzewski / facebook-authentication-adapter example snippets
namespace Lzakrzewski\FacebookAuthenticationAdapter\Adapter;
interface FacebookApi
{
const GRAPH_API_ME_URL = 'https://graph.facebook.com/v2.5/me';
const GRAPH_API_ACCESS_TOKEN_URL = 'https://graph.facebook.com/v2.5/oauth/access_token';
/**
* Returns access token during code exchange.
*
* @param $code
*
* @throws FacebookApiException
*
* @return string
*/
public function accessToken($code);
/**
* Returns a single user node as array.
*
* @param string $accessToken
* @param array $fields
*
* @throws FacebookApiException
*
* @return array
*/
public function me($accessToken, array $fields = array());
}
isset($_GET['code'])) {
header("Location: https://www.facebook.com/v2.5/dialog/oauth");
}
if (isset($_GET['code'])) {
$client = new GuzzleHttp\Client();
$adapter = new Lzakrzewski\FacebookAuthenticationAdapter\Adapter\GuzzleFacebookApi($client, 'http://my.host/login', 123123123123123, 'app-secret');
$accessToken = $adapter->accessToken($_GET['code']);
$userNode = $adapter->me($accessToken, array('first_name', 'last_name', 'gender', 'email', 'birthday', 'name'));
//Your own logic to process facebook user node
}