PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 4, 2022

[FIXED] Facebook login with php grapth sdk gives a 404 error

 February 04, 2022     facebook-graph-api, facebook-login, facebook-php-sdk, php     No comments   

Issue

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.



Answered By - Joshua
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing