Instapaper API 和JavaScript XAuth
我今天大部分时间都在尝试实现 Instapaper 的 XAuth API。我什至还无法获得 oauth 令牌。
知道我做错了什么吗?
我正在使用node.js和oauth模块。据我了解,我需要将用户名、密码、amd 模式作为额外参数传递。 oauth 模块应该处理所有 oauth 参数。但事实并非如此。这是代码:
var OAuth = require('oauth').OAuth;
var oauth = new OAuth(
'',
'https://www.instapaper.com/api/1/oauth/access_token',
'CONSUMER_KEY',
'CONSUMER_SECRET',
'1.0',
null,
'HMAC-SHA1',
null
);
var extra = {
'x_auth_username': 'USERNAME',
'x_auth_password': 'PASSWORD',
'x_auth_mode': 'client_auth'
};
var hello = oauth._prepareParameters('', '', 'POST', 'https://www.instapaper.com/api/1/oauth/access_token', null);
var url = 'https://www.instapaper.com/api/1/oauth/access_token';
var f = true;
for (var i in hello) {
if (f) {
url += '?';
f = false;
} else {
url += '&';
}
url += hello[i][0] + '=' + hello[i][1];
}
console.log(url+'&x_auth_mode=client_auth&x_auth_username=&x_auth_password=')
oauth._performSecureRequest('', '', "POST", url+'&x_auth_mode=client_auth&x_auth_username=&x_auth_password=', null, null, null, function(error, data, response) {
console.log(error, data)
});
它返回:
{ statusCode: 401,
data: 'oauth_signature [pWRf4W9k9nogID/O90Ng29bR2K0=] does not match expected value [eqJ8zD1bKeUa3InpDyegGDAbSnM=]' } 'oauth_signature [pWRf4W9k9nogID/O90Ng29bR2K0=] does not match expected value [eqJ8zD1bKeUa3InpDyegGDAbSnM=]'}
I've spent most of today try to implement Instapaper's XAuth API. I haven't even been able to get an oauth token, yet.
Any ideas what I'm doing wrong?
I'm using node.js and the oauth module. It's my understanding that I need to pass the username, password, amd mode as extra parameters. And the oauth module should take care of all of the oauth parameters. But it's not. Here's the code:
var OAuth = require('oauth').OAuth;
var oauth = new OAuth(
'',
'https://www.instapaper.com/api/1/oauth/access_token',
'CONSUMER_KEY',
'CONSUMER_SECRET',
'1.0',
null,
'HMAC-SHA1',
null
);
var extra = {
'x_auth_username': 'USERNAME',
'x_auth_password': 'PASSWORD',
'x_auth_mode': 'client_auth'
};
var hello = oauth._prepareParameters('', '', 'POST', 'https://www.instapaper.com/api/1/oauth/access_token', null);
var url = 'https://www.instapaper.com/api/1/oauth/access_token';
var f = true;
for (var i in hello) {
if (f) {
url += '?';
f = false;
} else {
url += '&';
}
url += hello[i][0] + '=' + hello[i][1];
}
console.log(url+'&x_auth_mode=client_auth&x_auth_username=&x_auth_password=')
oauth._performSecureRequest('', '', "POST", url+'&x_auth_mode=client_auth&x_auth_username=&x_auth_password=', null, null, null, function(error, data, response) {
console.log(error, data)
});
And it returns this:
{ statusCode: 401,
data: 'oauth_signature [pWRf4W9k9nogID/O90Ng29bR2K0=] does not match expected value [eqJ8zD1bKeUa3InpDyegGDAbSnM=]' } 'oauth_signature [pWRf4W9k9nogID/O90Ng29bR2K0=] does not match expected value [eqJ8zD1bKeUa3InpDyegGDAbSnM=]'}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我不确定这是否是
oauth
模块的错误,或者 Instapaper 的 API 在解析Authorization
标头时是否过于严格,但我必须在逗号作为标题分隔符。无论如何,这似乎是导致所有问题的原因(400 个错误)。oauth 目前构建的标头如下:
需要
我修改了
oauth.js
文件来反映这一点。https://github.com/ciaranj/node-oauth /blob/master/lib/oauth.js#L121
在行尾的逗号后面添加了一个空格
这是我的工作客户端示例:
希望这会有所帮助!
So I am not sure whether this is an error with the
oauth
module or if Instapaper's API is too strict in parsing theAuthorization
headers, but I had to add a space after the comma for the header delimiter. At any rate this seems to be causing all the issues (400 errors).oauth currently builds up headers as:
needed to be
I modified the
oauth.js
file to reflect this.https://github.com/ciaranj/node-oauth/blob/master/lib/oauth.js#L121
added a space after the comma towards the end of the line
Here is my working client sample:
Hope this helps!
Derek 的答案是正确的,因为缺少空格是问题所在,但您不需要编辑
oauth.js
。创建OAuth客户端后,只需设置分隔符字符串:(
是的,“sepErator”,模块代码中有一个拼写错误)
Derek's answer is right about the missing space as being the problem, but you don't need to edit
oauth.js
.After creating the OAuth client, just set the separator string:
(yes, "sepErator", there's a typo in the module's code)