The PHP SDK provides a rich set of server-side functionality for accessing Facebook’s server-side API calls. These include all of the features of the Graph API, FQL, and the Deprecated REST API.
You can download the Facebook PHP SDK from GitHub here.
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.
The PHP SDK can work in conjunction with the JavaScript SDK to provide seamless session management across both the client- and server-sides of an app.
To install the PHP 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 Facebook object with, at a minimum, your app id and app secret:
require_once("facebook.php");
$config = array();
$config[‘appId’] = 'YOUR_APP_ID';
$config[‘secret’] = 'YOUR_APP_SECRET';
$config[‘fileUpload’] = false; // optional
$facebook = new Facebook($config);
The optional fileUpload parameter tells the SDK whether or not file uploads are enabled on your server. See the setFileUploadSupport documentation for more details.
The PHP SDK can be used to support registration and login to your site using the users’ Facebook account. On the server-side, the PHP SDK provides helper-methods to simply login, request permissions, and logout. This functionality is provided by the Facebook::getUser(), Facebook::getLoginUrl() and Facebook::getLogoutUrl() methods.
Used in conjunction with the JavaScript SDK, the PHP SDK can share user sessions seamlessly across the client and server. If a user is already logged in to their Facebook account, the JavaScript SDK will pick up the login session and send it to the server via a cookie, which the PHP SDK reads without any intervention on the developer's part. Example here.
Link to download the PHP SDK (redirects to GitHub).
Call a Graph API method, FQL Query, or (DEPRECATED) REST API 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. OAuthException.