The 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 SDK greatly simplifies the process of authentication and authorizing users for your app.
- Download the SDK and obtain App ID
- Installing and initializing
- Authentication and authorization
- Next steps
Download the SDK and obtain App ID
Before you get started, download the Facebook SDK for PHP from GitHub.
You will need an App ID to initialize the SDK, which you can obtain from the App Dashboard.
Installing and initializing
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 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 setFileUploadSupportdocumentation for more details.-
Authentication and authorization
The SDK can be used to support authentication for 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 Facebook::getUser(),Facebook::getLoginUrl() and Facebook::getLogoutUrl() methods.
To enable this functionality, ensure that when you embed and initialise the JS SDK, you set both the status and the cookieparameters of the object passed to FB.init() to true.
For more details about the Facebook SDK for PHP, including complete class documentation, see the Facebook SDK for PHP Reference.
A sample SDK signing: http://vk.com/