Issue
I'm working non a my web based project, that work with the GMB API, all the libraries about Google api and theri requirements are installed with php composer. Now I need to work also with Facebook Api.. so I installed also this library with composer.
How i can see in the Documentation both the API needs guzzlehttp lib, to process the token.. ok!
The problem probably is that the google token conflict with the facebook one, causing this Fatal Error:
[23-Oct-2020 12:39:12 Europe/Rome] PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
"error": "invalid_grant",
"error_description": "Malformed auth code."
}
in /home/logictot2/public_html/sdtest/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:111
Stack trace:
#0 /home/logictot2/public_html/sdtest/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/logictot2/public_html/sdtest/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/logictot2/public_html/sdtest/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home/logictot2/public_html/sdtest/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
# in /home/logictot2/public_html/sdtest/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 111
So i try in the Facebook configuration to set up the curl instead the guzzle lib, but the error persist:
$fb = new Facebook\Facebook([
'app_id' => $your_app_id,
'app_secret' => $your_app_secret,
'default_graph_version' => 'v8.0',
'http_client_handler' => 'curl' //I added here the curl instead 'guzzle'
]);
The page work since a done the login with facebook, after this login that give me the token the above error occurs.
This is the test code that I'm using:
What I'm doing wrong..
require __DIR__.'/vendor/autoload.php';
session_start();
$your_app_id = 'XXXXXXXXXXX';
$your_app_secret = 'XXXXe803e5cXXXdXXXXf5ae1afacXXd3';
$fb = new Facebook\Facebook([
'app_id' => $your_app_id,
'app_secret' => $your_app_secret,
'default_graph_version' => 'v8.0',
'http_client_handler' => 'curl'
]);
if(!isset($accessToken)) {
$helper = $fb->getRedirectLoginHelper();
if ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl('https://www.logicamente.it/sdtest/prova.php', $permissions);
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
}else{
try {
$accessToken = $helper->getAccessToken();
echo '<h3>Access Token</h3>';
//var_dump($accessToken->getValue());
} catch(Facebook\Exception\ResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exception\SDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
}
Solution
I solved! The problem is in the 'guzzle' library version.
I the composer.json file I added the line "guzzlehttp/guzzle": "^5" inside the require object.
After that I launch the command composer update and when the library were downgraded the problem was solved.
Answered By - RIKIPB
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.