Please read this tutorial carefully, it will guide you through installation process step by step and ensure correct working of Facebook PHP SDK, as well as correct work of official Facebook Graph API for PHP. To install Facebook PHP SDK in your applications, be sure that you that you always use the newest version. Download link for the newest version will be provided immediately after payment is proceeded. If you are registered user, download link will be sent to you by email for any new release.



After you download the toolkit, unzip downloaded file and open 'library' folder. You will find there a folder 'faceconn'. Copy the 'faceconn' directory with all content in root folder of your PHP project. If you have not already done it, find facebook.php, base_facebook.php and fb_ca_chain_bundle.crt files in 'Library' folder and copy it also in root folder of your PHP project. The best option is to download the newest version of facebook.php file from official Facebook download site.

It is not required to copy facebook.php file and 'faceconn' folder in root folder of your PHP project, but it is compatible with code examples in tutorials on the site.


Setting Facebook keys

When all required files and folders are copied in your project, open 'AppConfig.php' file inside 'faceconn' folder and replace existing keys with Facebook application keys you stored while you were reading previous tutorial Create Facebook Application. Here is a part of code from 'AppConfig.php' which has to be changed with your Facebook application keys:

private static $ApiId = '142425069114172';
private static $Secret = '52a7c350e39c347d9699b57068a5d275';



Setting Application name and canvas page url

After setting of application keys in 'AppConfig.php', you have to also set the Facebook application name and canvas page in the same file. Settings of application name and canvas page are used as defaults and so avoid setting of the same stuff in several places of the code.

private static $AppName = 'FConn';
private static $AppCanvasUrl = 'http://apps.facebook.com/yourapp/';



Page requirements

There are couple of steps which have to be made on each page inside PHP project to allow correct work of Facebook Graph API and XFBML. First, there is requirement on <html> tag. It has to be set like this:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">

Immediately after <body> add following PHP code to include and initialize Facebook PHP SDK and official Facebook Graph API SDK.

<?php
require_once 'facebook.php';
require_once 'faceconn/faceconn.php';
UseGraphAPI();
?>

The first line of PHP code (require_once 'facebook.php';) is including of official Facebook PHP library, the second line (require_once 'faceconn/faceconn.php';) includes complete toolkit in your page and the third one (UseGraphAPI();) makes complete initialization of Facebook Graph API JavaScript SDK and XFBML. After these lines, it is possible to execute any Facebook Graph API calls in both PHP and JavaScript, and also to put any XFBML tag to work. To spare your time and make your code clean and easier to maintain, avoid using of JavaScript and XFBML and use components from Facebook PHP SDK.


Next: Solving Common Issues