FB SDK produces a PHP Fatal error

别说谁变了你拦得住时间么 提交于 2019-12-01 14:21:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!