Twitter OAuth - 无效/过期的令牌 [英] Twitter OAuth - Invalid/Expired Token
本文介绍了Twitter OAuth - 无效/过期的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
twitter_login
twitter_login
$twitteroauth = new TwitterOAuth($this->__twitterKey, $this->__twitterSecret);
$request_token = $twitteroauth->getRequestToken(Router::url(array('action' => 'twitter', 'authorize'), true));
$this->Session->write('Twitter', $request_token);
if($twitteroauth->http_code==200){
// Let's generate the URL and redirect
$url = $twitteroauth->getAuthorizeURL($request_token['oauth_token']);
header('Location: '. $url);
} else {
$this->Session->setFlash('Something went wrong');
}
twitter_callback
twitter_callback
$data['oauth_verifier'] = $_GET['oauth_verifier'];
$data['oauth_token'] = $this->Session->read('Twitter.oauth_token');
$data['oauth_token_secret'] = $this->Session->read('Twitter.oauth_token_secret');
$twitteroauth = new TwitterOAuth($this->__twitterKey, $this->__twitterSecret, $data['oauth_token'], $data['oauth_token_secret']);
$access_token = $twitteroauth->getAccessToken($data['oauth_verifier']);
当我执行 var_dump 时
When i do a var_dump
我得到以下内容
Array
(
[ "1.0" encoding="UTF-8"?>
/oauth/access_token?oauth_consumer_key=Z2R8QqJYCthif67Qba4vzA
[amp;oauth_nonce] => 78576d8eaaabb422fdbd3097e385adcc
[amp;oauth_signature] => T23hCeJ5PM2rdYvdZ0mvoHzOfLk=
[amp;oauth_signature_method] => HMAC-SHA1
[amp;oauth_timestamp] => 1301392825
[amp;oauth_token] => JKlpOBGaENFzuXbs4bSzVZCTWnelKX5WeJ1EA1MLfB0
[amp;oauth_verifier] => ifPBR18Pw2iTs74GAqyFlLXbvQAoOgG3AjWpPxXV2E
[amp;oauth_version] => 1.0
Invalid / expired Token
)
推荐答案
在 $twitteroauth = new TwitterOAuth(...) 之前尝试 ksorting大多数时候,OAuth 问题的出现是因为协议的要求.
Try ksorting just before $twitteroauth = new TwitterOAuth(...) Most of the times, OAuth problems occur because of the requirements of the protocol.
$data['oauth_token_secret'] = $this->Session->read('Twitter.oauth_token_secret');
ksort($data);
$twitteroauth = new TwitterOAuth($this->__twitterKey, $this->__twitterSecret,
这是一个解释参数归一化(排序)的链接http://oauth.net/core/1.0/#anchor14
Here is a link explaining the normalization (sorting) of the parameters http://oauth.net/core/1.0/#anchor14
这篇关于Twitter OAuth - 无效/过期的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文