diego1araujo / facebook

Facebook PHP SDK v4 for Laravel 4

Home Page:https://packagist.org/packages/pingpong/facebook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Facebook PHP SDK v4 for Laravel 4

Build Status Coverage Status

Server Requirement

This package is require PHP 5.4 or higher.

Installation

Open your composer.json file, and add the new required package.

   "pingpong/facebook": "1.0.*"

Next, open a terminal and run.

composer update

Next, Add new service provider in app/config/app.php.

  'Pingpong\Facebook\FacebookServiceProvider',

Next, Add new aliases in app/config/app.php.

   'Facebook' => 'Pingpong\Facebook\Facades\Facebook',

Next, publish the configuration.

php artisan config:publish pingpong/facebook

Done.

Usage

First, you must set the app_id and the app_secret in the configuration file. You can also set the default scope and the redirect url.

return array(
	'app_id'		=>	'',
	'app_secret'	=>	'',
	'redirect_url'	=>	url('facebook/callback'),
	'scope'			=>  array(
		'publish_actions',
		'email'
	)
);

Get facebook login url.

Facebook::getLoginUrl();

You can also update the scope.

$scope = array('email');

Facebook::getLoginUrl($scope);

Authenticate the user and get the permissions. This will automatically redirect the user to the facebook login url.

Facebook::authenticate();

If you want to update/override the scope, you can add the scope in the first parameter.

$scope = array('email');

Facebook::authenticate($scope);

You can also set the version of Facebook API want to use.

$version = 'the-version';
$scope = array('email');

Facebook::authenticate($scope, $version);

Get user profile for the current logged in user.

Facebook::getProfile();

Get call back from redirect. Will return a value of true if the authentication is successful and otherwise.

Facebook::getCallback();

Logout the current active user.

Facebook::destroy();
// or
Facebook::logout();

Call the Facebook API.

Facebook::api($method, $path, $parameters, $version);

Facebook::api('GET', '/me');

Facebook::api('POST', '/me/feed', $parameters);

Facebook::api('PUT', '/path', $parameters);

Facebook::api('PATCH', '/path', $parameters);

Facebook::api('DELETE', '/path/to', $parameters);

Helper method for call Facebook API.

GET Request

Facebook::get('/path', $parameters);

POST Request

Facebook::post('/path', $parameters);

PUT Request

Facebook::put('/path', $parameters);

PATCH Request

Facebook::patch('/me', $parameters);

DELETE Request

Facebook::delete('/me', $parameters);

Example

Authentication and authorization

Route::group(['prefix' => 'facebook'], function ()
{
	Route::get('connect', function ()
	{
		return Facebook::authenticate();
	});

	Route::get('callback', function ()
	{
		$callback = Facebook::getCallback();

		if($callback)
		{
			$profile = Facebook::getProfile();
			
			dd($profile);
		}

		dd($callback);
	});
});

License

This package is open-sourced software licensed under The BSD 3-Clause License

About

Facebook PHP SDK v4 for Laravel 4

https://packagist.org/packages/pingpong/facebook

License:BSD 3-Clause "New" or "Revised" License