At first my code was like this without use namespace but as per the documentation https://developers.facebook.com/docs/php/gettingstarted
session_start();
define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__ . '/Facebook/');
require_once __DIR__ . '/Facebook/autoload.php';
$fb= new Facebook/Facebook([
'app_id' => '******',
'app_secret' => '********************',
'default_graph_version' =>'v2.5'
]);
$fb->getRedirectLoginHelper();
//$permissions = ['email','id', 'first_name', 'last_name'];
$loginUrl = $fb->getLoginUrl('index.php');
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
but it throwed the following error
Fatal error: Class 'Facebook' not found in E:\wamp\www\sugumar\facebooklogin\index.php on line 9 Call Stack
So searched online and found the following link 'Class 'Facebook\Facebook' not found" Facebook SDK error
Which told me include the sdk file and use namespace, since I already included the sdk files, I put use Facebook\Facebook; at the top
so my code becomes
use Facebook\Facebook;
session_start();
define('FACEBOOK_SDK_V4_SRC_DIR', __DIR__ . '/Facebook/');
require_once __DIR__ . '/Facebook/autoload.php';
$fb= new Facebook/Facebook([
'app_id' => '********',
'app_secret' => '********************',
'default_graph_version' =>'v2.5'
]);
$fb->getRedirectLoginHelper();
//$permissions = ['email','id', 'first_name', 'last_name'];
$loginUrl = $fb->getLoginUrl('index.php');
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
But now it throws a different error, my appid and secret are correct... I am just trying to change from version 4 to version 5.
The error is
( ! ) Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID"' in E:\wamp\www\sugumar\facebooklogin\Facebook\Facebook.php on line 133
( ! ) Facebook\Exceptions\FacebookSDKException: Required "app_id" key not supplied in config and could not find fallback environment variable "FACEBOOK_APP_ID" in E:\wamp\www\sugumar\facebooklogin\Facebook\Facebook.php on line 133