https://github.com/adrian7/facebook-api
Simple Facebook API wrapper for PHP
https://github.com/adrian7/facebook-api
facebook-api facebook-php-sdk
Last synced: 6 months ago
JSON representation
Simple Facebook API wrapper for PHP
- Host: GitHub
- URL: https://github.com/adrian7/facebook-api
- Owner: adrian7
- License: mit
- Archived: true
- Created: 2017-09-30T12:59:14.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-12T20:21:51.000Z (over 8 years ago)
- Last Synced: 2024-12-14T18:46:26.612Z (over 1 year ago)
- Topics: facebook-api, facebook-php-sdk
- Language: PHP
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Devlib/Facebook-API
Simple Facebook API wrapper for PHP
### Install
`composer require devlib/facebook-api`
### Usage
```php
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
```php
//display link for authentication
echo 'Login with Facebook';
```
### Retrieve user info
```php
try{
$user = $app->getUser();
$data = $user->get(['id', 'name', 'email'])->getGraphUser();
//successful log in
echo ( '
#' . $data->getId() . ' ' . $data->getEmail() );
}
catch (\Facebook\Exceptions\FacebookAuthorizationException $e){
echo ('Error: ' . $e->getMessage() );
}
```
### Facebook API Reference:
- [Permissions Reference - Facebook Login](https://developers.facebook.com/docs/facebook-login/permissions)
- [Graph API Reference](https://developers.facebook.com/docs/graph-api/reference/)