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 http://github.com/facebook/php-sdk/
Copy the facebook.php file in to your webroot and include this file in your php code.
require_once(‘facebook.php’);
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:
- pecl install json
- Add json.ini file in /etc/php.d/
- edit json.ini (in VI) and add this line: xtension=json.so
- 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
Sajith