devlib/facebook-api

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple facebook API wrapper

0.2 2017-10-02 18:36 UTC

This package is not auto-updated.

Last update: 2023-06-23 18:53:22 UTC


README

Simple Facebook API wrapper for PHP

Install

composer require devlib/facebook-api

Usage

use \DevLib\API\Facebook\App;

$appId     = getenv('FACEBOOK_APP_ID');
$appSecret = getenv('FACEBOOK_APP_SECRET');

$permissions = ['email', 'user_posts'];
$callback    = ('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?callback=1');

$app         = App::create($appId, $appSecret)
                   ->withPermissions($permissions)
                   ->withCallbackURL($callback);

Generate login url

//display link for authentication
echo '<a href="' . $app->getLoginURL() . '">Login with Facebook</a>';

Retrieve user info

try{

    $user = $app->getUser();
    $data = $user->get(['id', 'name', 'email'])->getGraphUser();

    //successful log in
    echo ( '<h3><i>#' . $data->getId() . '</i> ' . $data->getEmail() );

}
catch (\Facebook\Exceptions\FacebookAuthorizationException $e){
    echo ('Error: ' . $e->getMessage() );
}

Facebook API Reference: