Offline_access 弃用后的长期访问令牌
Facebook 弃用offline_access 权限阻碍了长期访问令牌的获取。尽管文档声称要扩展服务器端 OAuth 令牌,但实际情况却有所不同。
解决方案
要获取长期访问令牌,请使用 ExtendedAccessToken ()方法:
公共函数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'), 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'];
}
请记住在开发者应用的高级设置中启用“弃用离线访问”以确保功能。收到常规访问Token后调用该方法即可获取有效期为60天的有效Token。
以上是Offline_access 弃用后如何获取长期 Facebook 访问令牌?的详细内容。更多信息请关注PHP中文网其他相关文章!