Having an issue with catch (FacebookApiException $

2019-08-06 09:17发布

My facebook login code using php sdk isn't working. When I click on the login button in index.php, it opens a pop up where i enter my email and password and then it just brings me back to index.php with some code appended to the url like this:

http://localhost/test.php?code=AQAr4gedKEz01BGIGpIB5Ijh66bk9j7qhW9...etc

Also $user was returning 0 even after trying to login. I did some digging in base_facebook.php and found this. There is a function that gets an Access Token using the code from the url. It's on line 752 of base_facebook.php. That function is like this:

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;
    }
    .
    .
    .
}

Here, the code under catch (FacebookApiException $e) is getting executed and hence the functioning is returning false. Therefore there is no access token and hence i'm unable to login i guess.

I'm a bit of a noob and don't actually know what catch (FacebookApiException $e) does. Can anyone tell me how to fix this?

EDIT:

I tried adding print_r($e); like this:

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

and this is the error it printed out: link. What exactly is going wrong here?

0条回答
登录 后发表回答