我在 codeigniter
中使用Twitter登录这是我的代码:
Twitterouth.php
function getRequestToken($oauth_callback) {
$parameters = array();
$parameters['oauth_callback'] = $oauth_callback;
$request = $this->oAuthRequest($this->requestTokenURL(), 'POST', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
//in function
$request_token = $this->connection->getRequestToken(base_url('/twitter/callback'));
$this->session->set_userdata('request_token', $request_token['oauth_token']);
$this->session->set_userdata('request_token_secret', $request_token['oauth_token_secret']);
$url = $this->connection->getAuthorizeURL($request_token);
// in constructor
$this->connection = $this->twitteroauth->create($this->config->item('twitter_consumer_token'), $this->config->item('twitter_consumer_secret'));
当我点击按钮时,它转到控制器twitter和功能auth并第一次
$this->connection->http_code
返回401并在第二次请求时返回200
与第一次请求相同 返回错误是
A PHP Error was encountered
Severity: Notice
Message: Undefined index: oauth_token
Filename: libraries/Twitteroauth.php
Line Number: 84
A PHP Error was encountered
Severity: Notice
Message: Undefined index: oauth_token_secret
Filename: libraries/Twitteroauth.php
Line Number: 84
A PHP Error was encountered
Severity: Notice
Message: Undefined index: oauth_token
Filename: controllers/twitter.php
Line Number: 69
A PHP Error was encountered
Severity: Notice
Message: Undefined index: oauth_token_secret
Filename: controllers/twitter.php
Line Number: 70
A PHP Error was encountered
Severity: Notice
Message: Undefined index: oauth_token
Filename: libraries/Twitteroauth.php
Line Number: 96
Array ( [Failed to validate oauth signature and token] => )
并在第二次请求时将其返回:
Array ( [oauth_token] => xsSzDXfeiBNKsnwYcGDg9LLGlQST4KhT [oauth_token_secret] => JlkNeaoiLCKGybIENIPtBGi5eqZ09moF [oauth_callback_confirmed] => true )