Instapaper API & Javascript XAuth

天涯浪子 提交于 2019-12-05 05:08:26
Derek Reynolds

So I am not sure whether this is an error with the oauth module or if Instapaper's API is too strict in parsing the Authorization 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:

oauth_consumer_key=SomeKey,oauth_consumer_secret=SomeSecret...

needed to be

oauth_consumer_key=SomeKey, oauth_consumer_secret=SomeSecret...

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

authHeader+= "" + this._encodeData(orderedParameters[i][0])+"=\""+ this._encodeData(orderedParameters[i][1])+"\", ";

Here is my working client sample:

var OAuth = require('oauth').OAuth;

var consumerKey    = 'chill';
var consumerSecret = 'duck';

var oa = new OAuth(
  null,
  'https://www.instapaper.com/api/1/oauth/access_token',
  consumerKey,
  consumerSecret,
  '1.0',
  null,
  'HMAC-SHA1'
);

var x_auth_params = {
  'x_auth_mode': 'client_auth',
  'x_auth_password': 'yourpass',
  'x_auth_username': 'yourusername@whatever.com'
};

oa.getOAuthAccessToken(null, null, null, x_auth_params, function (err, token, tokenSecret, results) {

  // CAN HAZ TOKENS!
  console.log(token);
  console.log(tokenSecret);

  // ZOMG DATA!!!
  oa.get("https://www.instapaper.com/api/1/bookmarks/list", token, tokenSecret,  function (err, data, response) {

    console.log(data);

  });

});

Hope this helps!

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:

var OAuth = require('oauth').OAuth;
var oa = new OAuth({...});
oa._oauthParameterSeperator = ', ';

(yes, "sepErator", there's a typo in the module's code)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!