Offline_access 棄用後的長期存取權杖
Facebook 棄用權限。儘管文件聲稱要擴展伺服器端 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中文網其他相關文章!