martinbean / facebook-php-sdk-laravel
A wrapper for the Facebook PHP SDK to work nicely with Laravel.
Installs: 1 121
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 3
Open Issues: 0
Type:laravel-package
Requires
- php: >=5.4.0
- facebook/php-sdk-v4: 4.0.*
- illuminate/support: >=4.2
This package is not auto-updated.
Last update: 2020-08-21 18:50:38 UTC
README
A wrapper for the Facebook PHP SDK to work nicely with Laravel 4 or 5.
Installation
Add this package’s name to your Composer manifest:
"require": {
"martinbean/facebook-php-sdk-laravel": "0.2.*"
}
Usage
Simply use the FacebookRedirectLoginHelper
class bundled in this package
instead of the one in the Facebook PHP SDK. You can then use it as normal in
your controllers:
<?php use Facebook\FacebookRequest; use Facebook\FacebookSession; use Facebook\GraphUser; use MartinBean\Facebook\Laravel\FacebookRedirectLoginHelper; class FacebookController extends BaseController { public function redirect() { FacebookSession::setDefaultApplication( Config::get('services.facebook.client_id'), Config::get('services.facebook.client_secret') ); $redirectUrl = Request::url(); $helper = new FacebookRedirectLoginHelper($redirectUrl); if ($session = $helper->getSessionFromRedirect()) { $request = new FacebookRequest($session, 'GET', '/me'); $user = $request->execute()->getGraphObject(GraphUser::className()); return Response::make('Hello, '.$user->getName()); } return Redirect::to($helper->getLoginUrl()); } }
Note the namespace at the top of the file: MartinBean\Facebook\Laravel\FacebookRedirectLoginHelper
;
License
Licensed under the MIT License.