Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Latest commit

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Devlib/Facebook-API

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 authenticationecho'<a href="' . $app->getLoginURL() . '">Login with Facebook</a>';

Retrieve user info

try{
$user = $app->getUser();
$data = $user->get(['id', 'name', 'email'])->getGraphUser();
//successful log inecho ( '<h3><i>#' . $data->getId() . '</i> ' . $data->getEmail() );
}
catch (\Facebook\Exceptions\FacebookAuthorizationException$e){
echo ('Error: ' . $e->getMessage() );
}

Facebook API Reference:

About

Simple Facebook API wrapper for PHP

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages