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
$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
时我得到以下
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
)
答案 0 :(得分:3)
在$ twitteroauth = new TwitterOAuth(...)之前尝试ksorting 大多数情况下,OAuth问题是由于协议的要求而发生的。
$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
答案 1 :(得分:0)
尝试将OAuth oauth_timestamp增加几个小时。
在PHP OAuth客户端中,它看起来像这样:
private static function generate_timestamp() {
return time()+5*3600;
}
<强>资源强>
http://www.backwardcompatible.net/149-Twitter-Timestamp-out-of-bounds-solved