I take no credit for this at all, this is all boparaiamrit's work, this is just to preserve my sanity while they update they're package.
Facebook
Facebook PHP SDK for Laravel, (*1)
Add boparaiamrit/facebook to composer.json., (*2)
"boparaiamrit/facebook": "dev-master"
Run composer update to pull down the latest version of Twitter., (*3)
Now open up app/config/app.php and add the service provider to your providers array., (*4)
'providers' => array(
'Boparaiamrit\Facebook\FacebookServiceProvider',
)
Now add the alias., (*5)
'aliases' => array(
'Facebook' => 'Boparaiamrit\Facebook\FacebookFacade',
)
Configuration
Run php artisan config:publish boparaiamrit/facebook and modify the config file with your own informations., (*6)
- AppId => If you donot have appId then get it from facebook developer apps.
- Secret => Its come with appId.
- Redirect => Specify redirect url after logged in with facebook.
- Logout => When somebody logout from your site, it redirects to logout url.
- Scope => These are permission you want from your users.
Examples
-
Get Login Url with your credentials and scope., (*7)
Route::get('/', function()
{
return Facebook::loginUrl();
});, (*8)
-
Get User Id, (*9)
Route::get('/', function()
{
return Facebook::getUser();
});, (*10)
-
Use facebook API, (*11)
Route::get('/', function()
{
$profile = Facebook::api('/me?fields=id,name,first_name,last_name,username,email,gender,birthday,hometown,location,picture.width(100)');
});, (*12)
-
Get Logout Url, (*13)
Route::get('/', function()
{
return Facebook::logoutUrl();
});, (*14)
-
FQL, (*15)
Route::get('/', function()
{
return Facebook::api(array(
'method' => 'fql.query',
'query' => "SELECT uid, sex, username, birthday, education, work FROM user WHERE uid = me()",
));
});, (*16)