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
How to Detect If Your Website Visitor Came from a Google Search Result
Convert This String to Timestamp PHP
Count of Duplicate Elements in an Array in PHP
Htaccess Rule to Parse PHP in HTML Files Not Working
Iterating Through a Stdclass Object in PHP
Best Way to Handle Dirty State in an Orm Model
Ssl Error Can Not Change to Tls
Extending Session Timeout in PHP via the .Htaccess
Call to Undefined Function Password_Hash()
How to Get the Last Dir from a Path in a String
Regular Expression for Checking Website Url
PHP Laravel: No Connection Could Be Made Because the Target MAChine Actively Refused It
The Ultimate Emoji Encoding Scheme
Is There Any Legitimate Use for Bare Strings in PHP
Php: Split String on Comma, But Not When Between Braces or Quotes