2016-09-18 70 views
0

我想知道Twitter是否有API端點與活動的過期訪問令牌交換。我現在有登錄流程的方式就是這樣。使用Twitter API刷新令牌

// Request a token and redirect to the authorization page 
$token = $this->twitter->getRequestToken(); 

// Set the session data 
$this->session->set_userdata('oauth_token', $token['oauth_token']); 
$this->session->set_userdata('oauth_token_secret', $token['oauth_token_secret']); 

// Redirect the user to the authorization page 
header('Location: https://api.twitter.com/oauth/authorize?oauth_token='.$token['oauth_token']); 

用戶重定向到的頁面將提示用戶在他們每次需要有效的訪問令牌時授權我的應用程序。在接受授權後,用戶將被重定向到回叫URL。在我的回調URL,將出現以下情況

// Get the parameters from the URL 
$token = $this->input->get('oauth_token'); 
$verifier = $this->input->get('oauth_verifier'); 

$oauthToken = $this->session->oauth_token; 
$oauthSecret = $this->session->oauth_token_secret; 

// Get the access token 
$access = $this->twitter->getAccessToken($verifier, $oauthToken, $oauthSecret); 

難道這樣的訪問令牌存在而產生,而無需授權每次我的每個應用程序和?

回答

0

根據Twitter's OAuth FAQ,除非用戶明確拒絕您的應用程序或管理員暫停您的應用程序,否則令牌不會過期。

如果您希望用戶能夠重複登錄而無需重新授權,則需要提供用於存儲令牌(cookie,數據庫等)的機制。