PHPackages                             simplon/facebook - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. simplon/facebook

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

simplon/facebook
================

Facebook Library

0.10.1(5y ago)24.7k1MITPHPPHP &gt;=7.1

Since Jan 14Pushed 5y agoCompare

[ Source](https://github.com/fightbulc/simplon_facebook)[ Packagist](https://packagist.org/packages/simplon/facebook)[ Docs](https://github.com/fightbulc/simplon_facebook)[ RSS](/packages/simplon-facebook/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (33)Used By (0)

```
     _                 _
 ___(_)_ __ ___  _ __ | | ___  _ __
/ __| | '_ ` _ \| '_ \| |/ _ \| '_ \
\__ \ | | | | | | |_) | | (_) | | | |
|___/_|_| |_| |_| .__/|_|\___/|_| |_|
                |_|
  __                _                 _
 / _| __ _  ___ ___| |__   ___   ___ | | __
| |_ / _` |/ __/ _ \ '_ \ / _ \ / _ \| |/ /
|  _| (_| | (_|  __/ |_) | (_) | (_) |   <
|_|  \__,_|\___\___|_.__/ \___/ \___/|_|\_\

```

Simplon/Facebook

---

1. Intro
--------

[](#1-intro)

This library helps you to communicate with `Facebook's graph API`. It's goal is to get you quickly started by solving common use issues which unfortunately occur quite often within Facebook's graph API.

---

2. Requirements
---------------

[](#2-requirements)

You will need a registered `Facebook app` in order to communicate with the API. Apps can be registered at [Facebooks Developers Portal](https://developers.facebook.com/). Simply have a look at `My Apps` and click `Add a new app`.

---

3. Install
----------

[](#3-install)

Easy install via composer. Still no idea what composer is? Inform yourself [here](http://getcomposer.org).

```
{
  "require": {
    "simplon/facebook": "*"
  }
}
```

---

4. User
-------

[](#4-user)

The following paragraphs demonstrate how to authenticate a user against your facebook app. It will also show how to `read an access token`, receive a `long term access token` and to `retrieve a user's data`.

### 4.1. Request access token

[](#41-request-access-token)

We need a url to which we will redirect the user in order to authenticate our app with the requested permissions. You will need a callback url for this. Facebook will redirect the user after handling the authentication process. This includes a cancellation as well.

For our little example we will go with the default permissions of `public_profile`. Permissions depend on what you would like to do on behalf of the user. [Here is a list](https://developers.facebook.com/docs/facebook-login/permissions#reference) of all possible permissions.

```
$appId = 'YOUR-APPID';
$appSecret = 'YOUR-APPSECRET';

// get a facebook app instance
$app = new FacebookApps($appId, $appSecret);

// we need a user instance
$user = new FacebookUsers($app, new FacebookPosts());

// callback url
$urlCallback = 'https://your-domain.com/callback/';

// we will fly with the default permissions: public_profile
$permissions = [];

// now lets build the url
$user->getUrlAuthentication($urlCallback, $permissions); // https://www.facebook.com/dialog/oauth?client_id=...

// redirect user to the given url...
```

After the user went through the authentication on Facebook's he/she will be redirected to your `callback url`. If the user cancelled the process you will receive the following `GET request`:

```
YOUR_CALLBACK_URL?
  error_reason=user_denied
  &error=access_denied
  &error_description=The+user+denied+your+request.

```

Otherwise you will receive an authentication code through the following `GET request`:

```
YOUR_CALLBACK_URL?
  code=AQBggnsv...

```

To finally receive an `access token` in order to work with it we need to use the given `code` and our pre-defined `callback url`:

```
$appId = 'YOUR-APPID';
$appSecret = 'YOUR-APPSECRET';

// get a facebook app instance
$app = new FacebookApps($appId, $appSecret);

// we need a user instance
$user = new FacebookUsers($app, new FacebookPosts());

$code = 'AQBggnsv...'; // received code
$urlCallback = 'https://your-domain.com/callback/'; // this needs to be the exact same url as before

// request access token
$user->requestAccessTokenByCode($code, $urlCallback)

// print token
echo $user->getAccessToken(); // CAANc8o7bTTcBAPyTZCwW....
```

If you did not receive any `FacebookException` you should hold now a `user's access token`. You need to save the `access token` so that you can make use of it.

**This token has usally a lifetime of 1 to 2 hours.** Read on to see how to request a `long term access token`.

### 4.2. Access token information

[](#42-access-token-information)

Wanna see what data are attached to an access token? Do the following:

```
$appId = 'YOUR-APPID';
$appSecret = 'YOUR-APPSECRET';

// your saved access token
$userAccessToken = 'CAANc8o7bTTcBAPyTZCwW....';

// get a facebook app instance
$app = new FacebookApps($appId, $appSecret);

// we need an app access token for this
$app->requestAccessToken();

// now we can have a look at the attached data for the user access token
$debugTokenVo = $app->getDebugTokenVo($userAccessToken); // have a look at the class DebugTokenData

// is this a short term token?
$debugTokenVo->isShortTermToken(); // bool
```

### 4.3. Request a long term access token

[](#43-request-a-long-term-access-token)

Lets assume we received a token and by having a look at its attached data we figured that its a `short term token`. Turn this token into a `60 days long term token`. When you received the new token make sure that you save it for later use.

```
$appId = 'YOUR-APPID';
$appSecret = 'YOUR-APPSECRET';

// your saved access token
$userAccessToken = 'CAANc8o7bTTcBAPyTZCwW....';

// get a facebook app instance
$app = new FacebookApps($appId, $appSecret);

// we need a user instance
$user = new FacebookUsers($app, new FacebookPosts());

// request long term token
$user->setAccessToken($userAccessToken)->requestLongTermAccessToken();

// your new token
$user->getAccessToken(); // save the new token away
```

There won't be any harm done if you have already a `long term token`.

### 4.4. Request user data

[](#44-request-user-data)

Alright, now that we have an access token we can do some requests - depending which [permissions you requested](https://developers.facebook.com/docs/facebook-login/permissions#reference). In our case we have the default permission of `public_profile`. The following example will request a user's data:

```
$appId = 'YOUR-APPID';
$appSecret = 'YOUR-APPSECRET';

// your saved access token
$userAccessToken = 'CAANc8o7bTTcBAPyTZCwW....';

// get a facebook app instance
$app = new FacebookApps($appId, $appSecret);

// we need a user instance
$user = new FacebookUsers($app, new FacebookPosts());

// fetch user data
$facebookUserDataVo = $user->setAccessToken($userAccessToken)->getUserData(); // the class holds all data

// lets print the name
$facebookUserDataVo->getFullName(); // Foo Bar
```

---

5. Page
-------

[](#5-page)

Soon to come.

6. Subscriptions
----------------

[](#6-subscriptions)

Soon to come.

---

License
=======

[](#license)

Simplon/Facebook is freely distributable under the terms of the MIT license.

Copyright (c) 2015 Tino Ehrich ()

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~185 days

Total

32

Last Release

2132d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.4

0.7.0PHP &gt;=7.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/451061?v=4)[Tino Ehrich](/maintainers/fightbulc)[@fightbulc](https://github.com/fightbulc)

---

Tags

httpapifacebook

### Embed Badge

![Health badge](/badges/simplon-facebook/health.svg)

```
[![Health](https://phpackages.com/badges/simplon-facebook/health.svg)](https://phpackages.com/packages/simplon-facebook)
```

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[bigcommerce/api

Enables PHP applications to communicate with the Bigcommerce API.

1501.1M8](/packages/bigcommerce-api)[quickbooks/payments-sdk

The Official PHP SDK for QuickBooks Online Payments API

2758.2k2](/packages/quickbooks-payments-sdk)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
