'Facebook Login in Codeigniter Facebook\Facebook class not found

I m trying to integtrate Facebook login in my website. I downloaded and integrated all library files in my web App directory. But i get an error.

An uncaught Exception was encountered Type: Error

Message: Class 'Facebook\Facebook' not found

Filename: C:\xampp\htdocs\fyp\application\libraries\Facebook.php

Line Number: 68

Backtrace:

File: C:\xampp\htdocs\fyp\application\controllers\User_authentication.php Line: 8 Function: library

File: C:\xampp\htdocs\fyp\index.php Line: 315 Function: require_once

C:\xampp\htdocs\fyp\application\libraries\Facebook.php here is code of Line No 68

if (!isset($this->fb))
{
    require_once 'facebook-php-sdk/autoload.php';
    $this->fb = new FB([
    'app_id'=> $this->config->item('facebook_app_id'),
    'app_secret'=> $this->config->item('facebook_app_secret'),
    'default_graph_version' => $this->config->item('facebook_graph_version')
]);
}

at the top of file i added line

use Facebook\Facebook as FB;


Solution 1:[1]

At the top of the file you have not required Facebook API yet.

Try to move require_once to the top also

require_once 'facebook-php-sdk/autoload.php';
use Facebook\Facebook as FB;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ryan M