Download the PHP package gajus/fuss without Composer
On this page you can find all versions of the php package gajus/fuss. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package fuss
Short Description The Facebook SDK for PHP provides an interface to the Graph API.
License BSD-3-Clause
Homepage https://github.com/gajus/fuss
Informations about the package fuss
Fuss
The Facebook SDK for PHP provides an interface to the Graph API. The main difference between the official PHP SDK and Fuss is the API.
Reinventing the Wheel
The original facebook/facebook-php-sdk is lacking separation of concerns. The facebook/facebook-php-sdk-v4 is a big step forward. Nonetheless, it came with its own evils that I could not live with (e.g. use of stateful programming and globals). The API itself is designed to cover all uses cases, which is expected of the official SDK, though not necessary needed for an average Facebook app. Fuss is trading some of the functionality in favor of a more intuitive API.
I am looking forward to hearing feedback either via [email protected] or in the issues section.
Fuss.js
Fuss.js is an extension of Fuss. It is designed for handling Facebook user authorization.
Everything Together
The following example is meant to cover the most common use scenario for Fuss. If you need further guidance, this document contains description of every Fuss SDK use-case and method.
Initializing App
You will need to have configured a Facebook App, which you can obtain from the App Dashboard.
Initialize the SDK with your app ID and secret:
In the original Facebook PHP SDK,
FacebookSession::setDefaultApplication
is used to set the default app credentials statically, making them accessible for future calls without needing to reference an equivalent of theGajus\Fuss\App
instance.
Options
The options are accepted at the time of constructing the app:
Gajus\Fuss\App::OPTION_VERSION
This option specifies the default version of the Graph API to use, e.g.
The above will produce a request against https://graph.facebook.com/v2.1/app
URL.
You can overwrite the default version at the time of making a request:
Excluding the version from the request path and not setting the Gajus\Fuss\App::OPTION_VERSION
will make all request URLs version-less, e.g.
The above will produce a request against https://graph.facebook.com/app
URL.
Gajus\Fuss\App::OPTION_FORCE_COOKIE
(experimental)
If enabled (default is disabled), Fuss SDK will attempt to set a cookie on clients that have explicitly opted not to accept third-party cookies. This is done by redirecting the user to the domain that needs to set the cookie and then redirecting user back to the Facebook Page Tab or Canvas URL. For more details, see the original issue.
Get the Signed Request
The signed request is encapsulated in the Gajus\Fuss\SignedRequest
entity. It is available via an instance of App
when either of the following is true:
- The signed request was received via the
$_POST['signed_request']
. - The signed request is present in the user session.
- The signed request is present in the JavaScript SDK cookie.
You might have obtained the signed request via the JavaScript SDK (e.g. FB.getLoginStatus). In which case, you can share it with the app:
The sign request is stored in the user session and can be retrieved on the following request.
Signed Request Data
A signed request contains some additional fields of information, even before permissions have been requested:
Get the User Access Token
The Gajus\Fuss\AccessToken
is available when either of the following is true:
- The signed request had the
access_token
. - The signed request had
code
that has been exchanged for the access token.
You can build an AccessToken
if you have it (e.g. stored in the database):
Extend The Access Token
Access tokens generated via web login are short-lived tokens, but you can upgrade them to long-lived tokens.
To check if the access token is long-lived:
To extend a short-lived access token:
To know when does the access token expire:
Take a string copy to store the access token for later use:
Initializing User
In order to make calls on behalf of a user, you need to create User
entity with a valid access token:
Upon instantiating the User
object, the access token is used to fetch information about the user.
You can update user access token:
Making Graph API calls
An API call can be made using either Gajus\Fuss\App
or Gajus\Fuss\User
context. If use App
context, then app access token is used; is use User
context, then user access token is used.
Page Tab
When an app is loaded in the page tab, the signed request contains information about the page itself. This information is abstracted using the PageTab
class:
The abstracted data is accessed via the following methods:
Installation
If you are using Composer as a package manager, add the following dependency to the composer.json
and run composer with the install parameter.
Tests
The tests are automatically run using the Travis-CI and secured app credentials.
To run the tests locally,
- Pull the repository using the Composer.
- Create
tests/config.php
fromtests/config.php.dist
and edit to add your credentials. - Execute the test script using the PHPUnit.
You should be using a sandboxed application for running the tests.