Laravel Facebook Graph API
Published on by Paul Redmond
Laravel Facebook Graph by Joel Butcher is a Laravel integration for the Graph PHP 8 SDK project. This package makes it easy to integrate the PHP SDK (provided by the same author) and Facebook login into your Laravel projects.
After you install this package and configure your app, you can use the provided Facebook facade/service to access the Facebook API:
// FacadeFacebook::getUser(array $params); // Service container making a GET requestapp(\JoelButcher\Facebook\Facebook::class)->get('/me', array $params);
Here's an example from the underlying PHP 8 SDK to get a user name and ID:
$fb = new Facebook\Facebook([ 'app_id' => '{app-id}', 'app_secret' => '{app-secret}', 'default_graph_version' => 'v2.10', ]); try { // Returns a `Facebook\Response` object $response = $fb->get('/me?fields=id,name', '{access-token}');} catch(Facebook\Exception\ResponseException $e) { echo 'Graph returned an error: ' . $e->getMessage(); exit;} catch(Facebook\Exception\SDKException $e) { echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit;} $user = $response->getGraphUser(); // Array accessecho 'Name: ' . $user['name'];// or getecho 'Name: ' . $user->getName();
Learn More
You can get started with this package by reading the documentation for the Graph PHP 8 SDK used by the Laravel wrapper. It includes plenty of examples.
To use this project in a Laravel app, check out joelbutcher/laravel-facebook-graph. Also, check out the PHP SDK used by the Laravel package.