lzakrzewski / facebook-authentication-adapter
Adapter for communication with Facebook GRAPH API
1.0.7
2016-02-07 15:38 UTC
Requires
- php: >=5.4
- guzzlehttp/guzzle: ~5.0
Requires (Dev)
- phpunit/phpunit: ~4.8
- psr/log: ~1.0
This package is not auto-updated.
Last update: 2024-11-15 18:46:47 UTC
README
Adapter for communication with Facebook GRAPH API.
FacebookAuthenticationAdapter is simple library for communication with Facebook GRAPH API. It returns access token and user node as array. Read about facebook api access tokens.
This library is independent part of FacebookAuthenticationBundle.
<?php 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()); }
Requirements
"require": { "php": ">=5.4", "guzzlehttp/guzzle": "~5.0" }
Supported Facebook API version
- v2.5
Installation
Require the library with composer:
composer require lzakrzewski/facebook-authentication-adapter "~1.0"
Example
<?php require 'vendor/autoload.php'; if (!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 }