Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Class 'Facebook\Facebook' not found" Facebook SDK error

Well I am new to facebook sdk. I have being following the guideline and performing the steps as written.. but I am getting this error and I dont know why?

 Fatal error: Class 'Facebook\Facebook' not found in C:\wamp\www\index.php on line 134

The error line code is:

<?php 
$fb = new Facebook\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.2',
  ]);
?>

This is not something I have made up, this is exactly the same code mentioned in facebook guideline! What should I do?

like image 925
Wocugon Avatar asked Sep 03 '15 03:09

Wocugon


1 Answers

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.

like image 163
q.Then Avatar answered Sep 20 '22 14:09

q.Then