FacebookSDK
Installation
- In composer.json, add require:
"bonbon1702/facebooksdk": "dev-master"
-
Run, (*1)
Composer update
-
In app/config/app.php:, (*2)
-Add providers, (*3)
'bonbon1702\Facebook\FbServiceProvider',
-Add aliases, (*4)
'Fb' => 'bonbon1702\Facebook\Facades\Fb',
- Publish the configuration:
php artisan config:publish bonbon1702/facebooksdk
- After that, you must config app_id and app_secret in
app/config/packages/bonbon1702/facebooksdk/config.php
```php
return array(
'app_id' => '',
'app_secret' => '',
'redirect_url' => url('facebook/callback'),
'scope' => array(
'publish_actions',
)
);, (*5)
Usage
------------
-Log in to Facebook
Fb::authenticate();, (*6)
-Check login(return boolean)
Fb::check(), (*7)
-Get user profile
Fb::getProfile()->asArray();, (*8)
-Get user profile picture
Fb::getUserProfilePicture($type)->asArray();($type is square,small,normal,large);, (*9)
-Publish posts to facebook
Fb::postToTimeLine($message, $link);, (*10)
Example
------------
```php
Route::group(['prefix' => 'facebook'], function ()
{
Route::get('connect', function ()
{
return Fb::authenticate();
});
Route::get('callback', function ()
{
$check = Fb::check();
if($check)
{
$profile = Fb::getProfile();
dd($profile);
}
});
});