Facebook登录语法错误

时间:2014-09-24 08:34:29

标签: php facebook

我一直在犯这个错误......

  

PHP Parse错误:语法错误,意外的T_OBJECT_OPERATOR       /home/public_html/vendor/facebook/php-sdk-v4/src/Facebook/FacebookRedirectLoginHelper.php on        第146行

  public function getSessionFromRedirect()
  {
    $this->loadState();
    if ($this->isValidRedirect()) {
      $params = array(
        'client_id' => FacebookSession::_getTargetAppId($this->appId),
        'redirect_uri' => $this->redirectUrl,
        'client_secret' =>
          FacebookSession::_getTargetAppSecret($this->appSecret),
        'code' => $this->getCode()
      );
      $response = (new FacebookRequest(
        FacebookSession::newAppSession($this->appId, $this->appSecret),
        'GET',
        '/oauth/access_token',
        $params
      ))->execute()->getResponse();
      if (isset($response['access_token'])) {
        return new FacebookSession($response['access_token']);
      }
    }
    return null;
  }

在这里,任何人都有任何想法?我正在发布一个错误,我发布了大部分代码,所以我将添加这个只是为了克服...:)

2 个答案:

答案 0 :(得分:0)

语法(new Something(arguments))->immediateMethodCall()被称为“解除引用”,并且仅在PHP 5.4中添加了对此的支持

您在此处收到错误的事实表明您没有使用PHP 5.4。我将根据错误消息的确切措辞猜测5.3。

您必须升级您的PHP版本才能与Facebook代码兼容。

答案 1 :(得分:0)

这可能有助于某人

$response = (array) (new FacebookRequest(
    FacebookSession::newAppSession($this->appId, $this->appSecret),
    'GET',
    '/oauth/access_token',
    $params
  ))->execute()->getResponse();

这是将返回对象强制转换为数组,因为后面的命令期望它不是对象而是数组。