Extending Access Token Expiration not functioning

两盒软妹~` 提交于 2019-12-01 21:49:15
Sudhir Bastakoti

I assume you need to enable "deprecate offline_access" in your Apps Advanced Settings page. As this worked for me:


//added code in base_facebook.php inside the facebook class
public function getExtendedAccessToken(){

    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(),
                                    'grant_type'=>'fb_exchange_token',
                                    'fb_exchange_token'=>$this->getAccessToken(),
                              ));

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

    $response_params = array();
    parse_str($access_token_response, $response_params);
    if (!isset($response_params['access_token'])) {
      return false;
    }

    return $response_params['access_token'];
}

The token can still be invalid for several reasons, See How-To: Handle expired access tokens. Hope it helps

Tom Lianza

There's a bug on this: https://developers.facebook.com/bugs/241373692605971

But, another question on SO has a workaround (user uninstalls and re-installs): fb_exchange_token for PHP only working once user removes app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!