Facebook SDK for PHP

The Facebook SDK for PHP 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 and FQL.

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

Before you get started, download the Facebook SDK for PHP from GitHub.

Download the PHP SDK

You will need an App ID to initialize the SDK, which you can obtain from the App Dashboard.

The Facebook SDK for PHP can work in conjunction with the Facebook SDK for JavaScript to provide seamless session management across both the client and server-sides of an app.


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.


Integration with the Facebook SDK for JavaScript

Used in conjunction with the Facebook SDK for JavaScript, the PHP SDK can share user sessions seamlessly across the client and server. If people are logged in with Facebook and have authorized your app, the JavaScript SDK can pick up the user session and persist this in a cookie, which the PHP SDK reads without any intervention on the developer’s part.

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.


Next steps

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/

Posted in Webs

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*