Argument 1 passed to Facebook\FacebookRequest::__construct() must be an instance of Facebook\FacebookSession, null given, called in

Do you get this error "Argument 1 passed to Facebook\FacebookRequest::__construct() must be an instance of Facebook\FacebookSession, null given, called in" with Facebook SDK?

In this tutorial I will explain how you can solve this error!

If you want to use the Facebook SDK for PHP v4, you must first download the SDK from here:

https://developers.facebook.com/docs/php/gettingstarted/4.0.0

Next, copy it on your server in folder, called Facebook. Then add this code in a file where you want to use the SDK:

define('FACEBOOK_SDK_V4_SRC_DIR', 'facebook/src/Facebook/');
require 'facebook/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
FacebookSession::setDefaultApplication('api id', 'api secret');

Now, to solve the error, add:

$session = new FacebookSession('access-token');
$session = FacebookSession::newAppSession();

and then:

$request = new FacebookRequest(
$session,
'GET',
''
);

In this way I have solved the error!









Leave a Comment