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:
1// Facade2Facebook::getUser(array $params);3 4// Service container making a GET request5app(\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:
1$fb = new Facebook\Facebook([ 2 'app_id' => '{app-id}', 3 'app_secret' => '{app-secret}', 4 'default_graph_version' => 'v2.10', 5 ]); 6 7try { 8 // Returns a `Facebook\Response` object 9 $response = $fb->get('/me?fields=id,name', '{access-token}');10} catch(Facebook\Exception\ResponseException $e) {11 echo 'Graph returned an error: ' . $e->getMessage();12 exit;13} catch(Facebook\Exception\SDKException $e) {14 echo 'Facebook SDK returned an error: ' . $e->getMessage();15 exit;16}17 18$user = $response->getGraphUser();19 20// Array access21echo 'Name: ' . $user['name'];22// or get23echo 'Name: ' . $user->getName();
0 comments:
Post a Comment
Thanks