-1

So i use PHP SDK 3.2.2 and i can not change to 4.0.0 branch because i don't have new PHP version on my server. Every application using FB API starts to redirect indefinite and is not working. There is no error, no notification. Facebook does not report any breaking change to this version of PHP SDK in App Dashboard or on the dev blog.

What to do so my Apps start to work properly again?

Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236

1 Answers1

1

Open base_facebook.php and change this function to this form:

 protected function getAccessTokenFromCode($code, $redirect_uri = null) {
    if (empty($code)) {
      return false;
    }

    if ($redirect_uri === null) {
      $redirect_uri = $this->getCurrentUrl();
    }

    try {

      $access_token_response = json_decode(
        $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;
    }

    if (empty($access_token_response)) {
      return false;
    }

    if (!isset($access_token_response->access_token)) {
      return false;
    }



    return $access_token_response->access_token;
  }

$access_token_response is no longer a serialised array, but a JSON. So you need to parse JSON and return access_token from it.

Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236