You can download the Facebook SDK for PHP from GitHub.
The PHP SDK is typically used to perform operations as an app administrator, but can also be used to perform operations on behalf of the current session user. By removing the need to manage access tokens manually, the PHP SDK greatly simplifies the process of authentication and authorizing users for your app.
You will need an app id to initialize the SDK, which you can obtain from the App Dashboard.
To install the SDK, extract the downloaded files and copy the files from the
src/ directory to a directory on the server where you will host your app, for example
php-sdk. Then, just include
php-sdk/facebook.php wherever you want to use the SDK. You use the SDK by instantiating a new
require_once("facebook.php"); $config = array(); $config['appId'] = 'YOUR_APP_ID'; $config['secret'] = 'YOUR_APP_SECRET'; $config['fileUpload'] = false; // optional $facebook = new Facebook($config);
fileUpload parameter tells the SDK whether or not file uploads are enabled on your server. See the setFileUploadSupport documentation for more details.
The SDK can be used to support authentication your site using the users' Facebook account. On the server-side, the SDK provides helper-methods to authentication, requesting permissions, and logout. This functionality is provided by the
To enable this functionality, ensure that when you embed and initialise the JS SDK, you set both the
status and the
cookie parameters of the object passed to
Call a Graph API method or an FQL Query using the PHP SDK.
Get the current access token being used by the SDK.
Get the App secret that the SDK is currently using.
Get the App ID that the SDK is currently using.
Returns a URL based on the user’s login status on Facebook.
Get a URL that the user can click to login, authorize the app, and get redirected back to the app.
This method returns a URL that, when clicked by the user, will log them out of their Facebook session and then redirect them back to your application.
Get the current signed request being used by the SDK.
This method returns the Facebook User ID of the current user, or 0 if there is no logged-in user.
Set the current access token being used by the SDK.
Set the App secret that the SDK is currently using.
Set the App ID that the SDK is currently using.
Set file upload support in the SDK.
Get whether file upload support has been enabled in the SDK.
Get the object that is the result of the error or exception returned by the server.
Get the type for the error or exception, e.g.