2

正如我们所知,offline_access 现在已被弃用,有人可以告诉我,如果没有该权限,我们如何获得长期存在的访问令牌?

4

1 回答 1

1

您可以通过将以下函数添加到 base_facebook.php 来扩展访问令牌。

// 用于扩展令牌值的扩展函数。

公共函数 getExtendedAccessToken() {

try {

    $access_token_response =
        $this->_oauthRequest(
            $this->getUrl('graph', '/oauth/access_token'),
            $params = array(    'client_id' => $this->getAppId(),
                                'client_secret' => $this->getApiSecret(),
                                'grant_type'=>'fb_exchange_token',
                                'fb_exchange_token'=>$this->getAccessToken(),
                          ));

} catch (FacebookApiException $e) {

  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'];

}

于 2012-04-20T15:15:23.627 回答