尝试获取请求令牌时,我收到了正文“无法验证 oauth 签名和令牌”的响应。
这是我用来设置所有请求参数的代码。我注意到一些有趣的地方,我认为这些地方可能是一堆星号的问题。
var appId = "myId"
, appSecret = "mySecret"
, redirectUrl = "http://localhost:8077/twitterLogin";
var d = new Date();
, time = Math.floor(d.getTime() / 1000); //seconds since epoch
var oauth_nonce = Math.random() * 1000000; //************could be the issue, maybe?
, oauth_callback = encodeURIComponent('http://localhost:8077/twitterLogin');
//****************more likely the issue
var paramString = encodeURIComponent('oauth_consumer_key=**MY_APP_ID**&oauth_callback='+ oauth_callback
+ '&oauth_nonce=' + oauth_nonce
+ '&oauth_signature_method=HMAC-SHA1&oauth_timestamp=' + time
+ '&=oauth_version=1.0');
var baseString = "POST&" + encodeURIComponent("https://api.twitter.com/oauth/request_token") + '&' + paramString;
var signingKey = encodeURIComponent(appSecret) + '&' + encodeURIComponent(appSecret);
, signature = crypto.createHmac('sha1', signingKey).update(baseString).digest('hex');
这是请求本身的代码:
var requestBody = "oauth_callback="+ oauth_callback
+ "&appId=" + appId
+ "&oauth_nonce=" + oauth_nonce
+ "&oauth_signature=" + signature
+ "&oauth_signature_method=HMAC-SHA1"
+ "&oauth_timestamp=" + time
+ "&oauth_version=1.0";
//*******also could be the issue. maybe missing headers or something?
request.post({url: 'https://api.twitter.com/oauth/request_token', body: requestBody});
我只是想知道签名或令牌缺少什么..