在使用twitter请求签名时无法验证oauth签名和令牌

时间:2015-01-09 05:19:31

标签: php codeigniter twitter oauth

我在 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 )
  • 问题是什么
  • 我做错了吗?
  • 我在localhost上测试这可能是因为这个问题(但是我在服务器上尝试了这个问题但同样的问题)

0 个答案:

没有答案