问题
First noticed [27-Mar-2017 17:47:16 GMT+0] a FB SDK integration that worked very well allowing people to login to our site via their Facebook account just stopped working. The server logs show the following error
PHP Fatal error: Cannot use object of type stdClass as array in fb-sdk/FacebookRedirectLoginHelper.php on line 191
We have not done any relevant code change that should have initiated it. Have we missed an upgrade?
回答1:
Suggested fix for line 191-193:
if (isset($response->access_token)) {
return new FacebookSession($response->access_token);
}
You can also try converting $response
to array but that won't be optimized solution. So, go ahead and try aforementioned solution.
Or try replacing in src/Facebook/FacebookRedirectLoginHelper.php
if (isset($response['access_token'])) {
return new FacebookSession($response['access_token']);
WITH
$accessToken = null;
if (is_object($response) && isset($response->access_token)) {
$accessToken = $response->access_token;
} elseif (is_array($response) && isset($response['access_token'])) {
$accessToken = $response['access_token'];
}
if (isset($accessToken)) {
return new FacebookSession($accessToken);
回答2:
Replace "$response['access_token']" with "$response->access_token" on line 186 and 187 in FacebookRedirectLoginHelper.php
回答3:
Better solution is to migrate to SDK 5 https://developers.facebook.com/docs/php/howto/example_facebook_login
来源:https://stackoverflow.com/questions/43069347/fb-sdk-produces-a-php-fatal-error