Search code examples
phpfacebook-graph-apifacebook-php-sdkfacebook-login

Facebook login with php grapth sdk gives a 404 error


I have a facebook login button on a site, which used to work. I haven't changed anything as far as I know, but now it just gives a Not Found error:

The requested URL /https://www.facebook.com/v3.0/dialog/oauth was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Not sure if it would help, but this is in my fbConfig.php file:

require_once __DIR__ . '/facebook-php-sdk/autoload.php';

// Include required libraries
use Facebook\Facebook;
use Facebook\Exceptions\FacebookResponseException;
use Facebook\Exceptions\FacebookSDKException;

//some code to set the correct $appId and $appSecret that developers.facebook gave me

$redirectURL   = $url; //Callback URL

$fbPermissions = array('email');  //Optional permissions

$fb = new Facebook(array(
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v3.0',
));

// Get redirect login helper
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state']=$_GET['state'];
// Try to get access token
try {
if(isset($_SESSION['facebook_access_token'])){
    $accessToken = $_SESSION['facebook_access_token'];
}else{
    $accessToken = $helper->getAccessToken();
}
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}

Solution

  • A cursory glance at The PHP Docs indicates the current default_graph_version version is v2.2. So that means 1 of 2 things:

    1. You're using a version that doesn't exist
    2. You're using a beta version which is caveat emptor

    Try bringing the version back to v2.2 and seeing if it works. Also ensure you're using an up-to-date, unmodified, official version of their SDKs.