Error: Class 'Facebook\Facebooksession' Not Found with the Facebook PHP Sdk

Error: Class 'Facebook\FacebookSession' not found with the facebook PHP SDK

I found the solution here

I did not code in php for some time now and things have changed. use Facebook\FacebookSession; is not enough. You need to add a require_once too.

require_once( 'Facebook/FacebookSession.php' );

Edit: for a more detailed solution, please checkout the answer below.

Class 'Facebook\Facebook' not found Facebook SDK error

You need to include the autoloader first to get access to the service methods and classes (as said in the PHP SDK Documentation for Facebook API. You are trying to use a namespaced class Facebook\Facebook, to use its methods, but you don't have the class in the PHP file.

require_once 'src/Facebook/autoload.php';
//Create the Facebook service
$fb = new Facebook\Facebook ([
'app_id' => '-----------------',
'app_secret' => '--------------------',
'default_graph_version' => 'v2.4'
]);

Somewhere in your directory (if you installed the Facebook PHP SDK) correctly, you will find the autoload.php file which automatically requires .php files that you need to use the services and methods.

class Facebook not found in laravel 5 facebook graph api

Within the index function, you are not in the global scope so that as you call the class as Facebook\Facebook, PHP thinks that you are calling Facebook\Facebook declared in the App\Http\Controllers\Userapp namespace.

Either you need to reference them as globally like below with prepending \.

public function index()
{
$fb = new \Facebook\Facebook([]);
// your code
catch(\Facebook\Exceptions\FacebookResponseException $e)
// your code
catch(\Facebook\Exceptions\FacebookSDKException $e)
// your code
}

Or use the aliases.

use Facebook\Facebook as Facebook;
use Facebook\Exceptions\FacebookResponseException as FacebookResponseException
use Facebook\Exceptions\FacebookSDKException as FacebookSDKException

public function index()
{
$fb = new Facebook([]);
// your code
catch(FacebookResponseException $e)
// your code
catch(FacebookSDKException $e)
// your code
}

Class 'Facebook\GraphObject' not found with Facebook PHP SDK 4

Now I found a good tutorial and solution for the Facebook SDK (v4) here.

It's 'funny' that a billion dollar company is not able to provide a decent documentation.



Related Topics



Leave a reply



Submit