0

我正在尝试使用 twitter 签署请求,以便获得请求令牌并卡住。我已经使用 twitter 在他们的文档中使用的信息来确保我的格式正确等等。我有相同的 Basestring 和 Key 但我仍然没有得到相同的签名。我看过其他几个例子,我似乎也做了同样的事情。

希望得到一些帮助来解决这个问题!

这是代码:

    private function sign_request($http_method, $url, $params, $oath)
    {
        // SET BASE STRING
        $sign_params    =   $this->set_sign_params($params, $oath);
        $sign_url       =   $this->set_sign_url($url);
        $base_string    =   $this->set_sign_basestring($http_method, $sign_params, $sign_url);

        print $base_string; // Output the same as the twitter example: POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Dhttp%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0


        // GET HMAC-SHA1 SIGNATURE
        if($this->signature_method == 'HMAC-SHA1')
        {               
            // SET KEY
            $key = $this->set_sign_key();

            print $key; // Output the same as the twitter example: MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98&

            //SIGN
            $signature = base64_encode(hash_hmac('sha1', $base_string, $key, true)); 

            print $signature; // DO NOT output the same as the twitter example. Twitteroutput: 8wUi7m5HFQy76nowoCThusfgB+Q= and my outout: Ewqbgi+AMRZGMcqwQTjhE5/ZD80= 
        }

        return $signature;
    }

我错过了什么?有人有任何想法吗?

还有一个“有趣”的事情是,如果我将签名设置为 twitter 示例中的签名,我仍然无法获得请求令牌......

先谢谢了!

4

1 回答 1

0

您的基本字符串与 Twitter 的不同。这就是为什么你会得到不同的签名。

推特:

POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0

你的:

POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Frequest_token&oauth_callback%3Dhttp%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11%26oauth_consumer_key%3DGDdmIQH6jhtmLUypg82g%26oauth_nonce%3DQP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1272323042%26oauth_version%3D1.0

区别在于oauth_callback变量。

推特:

oauth_callback%3Dhttp%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26

你的:

oauth_callback%3Dhttp%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11%26

于 2011-05-26T12:41:50.860 回答