新facebook T_OBJECT_OPERATOR错误

时间:2015-05-02 09:24:16

标签: php facebook

我收到此错误:

  

语法错误,意外T_OBJECT_OPERATOR

...中

$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;

这是错误行:))->execute()->getResponse();

1 个答案:

答案 0 :(得分:0)

虽然我的PHP版本是5.3(<5.4)。 在您的代码中,您试图在实例化时访问类成员,这是仅在PHP 5.4上引入的选项。

  

已添加实例化的类成员访问权限,例如(新   FOO) - &GT; bar()的

来源:http://php.net/manual/en/migration54.new-features.php

因此,您必须更改代码并将该部分分为两个步骤,如下所示:

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

$response = $fbRequest->execute()->getResponse();