Javascript 400 twitter oauth请求令牌上的错误请求

Javascript 400 twitter oauth请求令牌上的错误请求,javascript,extjs,twitter,oauth,Javascript,Extjs,Twitter,Oauth,我正在尝试向发送一个POST请求。响应为400个错误请求,没有任何信息。这是我的密码: onTwitterRegisterClick: function() { var callbackURL = 'http://test.loc:1841/', consumerKey = 'm59nSEhyF3Zp4gVdpDzq6CIPp', consumerSecret = 'Wou436sq4LUXwO1ajE2egdMdAfV9LtPLkG4JlCF4Yi5Yp

我正在尝试向发送一个POST请求。响应为400个错误请求,没有任何信息。这是我的密码:

onTwitterRegisterClick: function() {
    var callbackURL = 'http://test.loc:1841/',
        consumerKey = 'm59nSEhyF3Zp4gVdpDzq6CIPp',
        consumerSecret = 'Wou436sq4LUXwO1ajE2egdMdAfV9LtPLkG4JlCF4Yi5YpcrnTF',
        requestTokenURL = 'https://api.twitter.com/oauth/request_token';

    var time = new Date().valueOf().toString(),
        oauth_nonce = makeRandomString(32);
    var paramsForSignature = [
        encodeURIComponent('oauth_callback') + '=' + encodeURIComponent(callbackURL),
        encodeURIComponent('oauth_consumer_key') + '=' + encodeURIComponent(consumerKey),
        encodeURIComponent('oauth_nonce') + '=' + encodeURIComponent(oauth_nonce),
        encodeURIComponent('oauth_signature_method') + '=' + encodeURIComponent('HMAC-SHA1'),
        encodeURIComponent('oauth_timestamp') + '=' + encodeURIComponent(time),
        encodeURIComponent('oauth_version') + '=' + encodeURIComponent('1.0')
    ];
    var paramsForSignatureStr = paramsForSignature.join('&');

    var signatureBaseString = 'POST&' + encodeURIComponent(requestTokenURL) + '&' + encodeURIComponent(paramsForSignatureStr);

    //alert(signatureBaseString);
    var signature = btoa(CryptoJS.HmacSHA1(signatureBaseString, consumerSecret + '&'));
    //var signature = prompt('hmac-sha1 of signatureBaseString=' + CryptoJS.HmacSHA1(signatureBaseString, consumerSecret + '&'));
    //alert(signature);

    Ext.Ajax.request({
        method: 'POST',
        url: requestTokenURL,
        async: false,
        headers:{
            Authorization: 'OAuth oauth_callback="' + encodeURIComponent(callbackURL) + '", ' +
            'oauth_consumer_key="' + consumerKey + '", ' +
            'oauth_nonce="' + oauth_nonce + '", ' +
            'oauth_signature="' + encodeURIComponent(signature) + '", ' +
            'oauth_signature_method="HMAC-SHA1", ' +
            'oauth_timestamp="' + time + '", ' +
            'oauth_version="1.0"'
        },

        success: function(response, opts) {
            alert(response.responseText);
        },

        failure: function (response, opts) {
            alert(response.responseText);
        }
    })
}
我读了几遍官方指南。我做错了什么


我只注意到变量签名的值类似于YTg5ZmI2ZmEwMWU4MDkzMjlkZmEzMmVmMmVmYzgxMjlmZTJlNDdlZQ==和官方指南中的tnnArxj06cWHq44gCs1OSKk/jLY=不同,因为函数btoa使用字符串而不是整数。

尝试将异步:false更改为true

400错误请求意味着您的请求不正确正确,请使用开发人员工具或Firebug检查requestby ajax调用在浏览器中实际发送的内容,从中您可以获得线索。在我打开本主题之前,我已经这样做了。我检查了请求,没有发现任何错误。但响应仍然是400个错误请求。问题可能出在我做的签名上。但是我看不出有什么问题。希望它能帮助你