Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用php sdk登录facebook时遇到catch(FacebookApiException$e)问题_Php_Facebook Graph Api_Facebook Php Sdk_Facebook Login - Fatal编程技术网

在使用php sdk登录facebook时遇到catch(FacebookApiException$e)问题

在使用php sdk登录facebook时遇到catch(FacebookApiException$e)问题,php,facebook-graph-api,facebook-php-sdk,facebook-login,Php,Facebook Graph Api,Facebook Php Sdk,Facebook Login,我使用PHPSDK的facebook登录代码不起作用。当我点击index.php中的登录按钮时,它会打开一个弹出窗口,我在其中输入电子邮件和密码,然后它会将我带回index.php,并在url中附加一些代码,如下所示: http://localhost/test.php?code=AQAr4gedKEz01BGIGpIB5Ijh66bk9j7qhW9...etc protected function getAccessTokenFromCode($code, $redirect_uri = n

我使用PHPSDK的facebook登录代码不起作用。当我点击index.php中的登录按钮时,它会打开一个弹出窗口,我在其中输入电子邮件和密码,然后它会将我带回index.php,并在url中附加一些代码,如下所示:

http://localhost/test.php?code=AQAr4gedKEz01BGIGpIB5Ijh66bk9j7qhW9...etc
protected function getAccessTokenFromCode($code, $redirect_uri = null) {
    .
    .
    .
    try {
      // need to circumvent json_decode by calling _oauthRequest
      // directly, since response isn't JSON format.
      $access_token_response =
        $this->_oauthRequest(
          $this->getUrl('graph', '/oauth/access_token'),
          $params = array('client_id' => $this->getAppId(),
                          'client_secret' => $this->getAppSecret(),
                          'redirect_uri' => $redirect_uri,
                          'code' => $code));
    } catch (FacebookApiException $e) { 
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      return false;
    }
    .
    .
    .
}
catch (FacebookApiException $e) { 
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      print_r($e);
      return false;
}
另外,$user甚至在尝试登录后仍返回0。我在base_facebook.php中进行了一些挖掘,发现了这个。有一个函数使用url中的代码获取访问令牌。它位于base_facebook.php的第752行。该函数如下所示:

http://localhost/test.php?code=AQAr4gedKEz01BGIGpIB5Ijh66bk9j7qhW9...etc
protected function getAccessTokenFromCode($code, $redirect_uri = null) {
    .
    .
    .
    try {
      // need to circumvent json_decode by calling _oauthRequest
      // directly, since response isn't JSON format.
      $access_token_response =
        $this->_oauthRequest(
          $this->getUrl('graph', '/oauth/access_token'),
          $params = array('client_id' => $this->getAppId(),
                          'client_secret' => $this->getAppSecret(),
                          'redirect_uri' => $redirect_uri,
                          'code' => $code));
    } catch (FacebookApiException $e) { 
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      return false;
    }
    .
    .
    .
}
catch (FacebookApiException $e) { 
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      print_r($e);
      return false;
}
这里,catch(FacebookApiException$e)下的代码正在执行,因此函数返回false。因此没有访问令牌,因此我想我无法登录

我有点不知道catch(FaceBookApiexException$e)是做什么的。谁能告诉我怎么解决这个问题吗

编辑:

我尝试添加print\r($e)像这样:

http://localhost/test.php?code=AQAr4gedKEz01BGIGpIB5Ijh66bk9j7qhW9...etc
protected function getAccessTokenFromCode($code, $redirect_uri = null) {
    .
    .
    .
    try {
      // need to circumvent json_decode by calling _oauthRequest
      // directly, since response isn't JSON format.
      $access_token_response =
        $this->_oauthRequest(
          $this->getUrl('graph', '/oauth/access_token'),
          $params = array('client_id' => $this->getAppId(),
                          'client_secret' => $this->getAppSecret(),
                          'redirect_uri' => $redirect_uri,
                          'code' => $code));
    } catch (FacebookApiException $e) { 
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      return false;
    }
    .
    .
    .
}
catch (FacebookApiException $e) { 
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      print_r($e);
      return false;
}

这是它打印出来的错误:。这里到底出了什么问题?

考虑试用新版SDK:docs:@Fosco谢谢你的建议。我刚试完,同样的事情正在发生。我只剩下带?code=..的url了。。。。附加到它,而不是登录。你应该使用Facebook的重定向url的特定页面,并在该页面上使用FacebookRedirectLoginHelper使用getSessionFromRedirect处理代码。我尝试将其重定向到其他页面,并按照你说的做。但是没有运气。url中的代码没有得到处理。我觉得问题出在我的环境中,因为相同的问题在sdk的两个版本中重复出现。@Fosco,请查看编辑。