Like the old REST API, you don’t need to add 2-3 files for Facebook PHP SDK. The new graph api comes in a single file which is located at

Copy the facebook.php file in to your webroot and include this file in your php code.


To work fully functional, you need CURL and JSON installed in your server. To check this use phpinfo() function.

To make sure, these missing is the main problem, add exit(‘Curl error’); just above the line throw new Exception(‘Facebook needs the CURL PHP extension.’); in facebook.php file.

Same for JSON.

The Linux way of installing CURL is :

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

To install JSON in your linux machine, follow these steps:

  1. pecl install json
  2. Add json.ini file in /etc/php.d/
  3. edit json.ini (in VI) and add this line:
  4. Save the file and restart appache (/etc/init.d/httpd restart) or apache2 restart depends on your linux OS

See the example.php file in php-sdk from Github, if you call getSession function, you only get a NULL string if you are not logged in proper way. So I recommend to redirect into login page if there is no session available.

Here is the change:

if (! $facebook->getSession()) {

header(‘Location: ‘.$facebook->getLoginUrl());


Then try the rest of the part as per example.php , it will work

Good Luck