AvianFlu / ntwitter

Asynchronous Twitter REST/stream/search client API for node.js

Home Page:https://github.com/AvianFlu/ntwitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v0.5.0 updateStatus error

twojcik opened this issue · comments

Hi,
When I updated code to v0.5.0 updateStatus function returns :

{"errors":[{"message":"Could not authenticate you","code":32}]}

Reverting back to 0.4 works . I assume it's connected with twitter API 1.1 ?

Same error for me, any ideas?

My code:

var twitter = require('ntwitter');
var credentials = require('./credentials.js');

var t = new twitter({
    consumer_key: credentials.consumer_key,
    consumer_secret: credentials.consumer_secret,
    access_token_key: credentials.access_token_key,
    access_token_secret: credentials.access_token_secret
});

t.stream('user', {'with':'user'}, function(stream) {
  stream.on('data', function (data) {
    // console.log(data);
    if ('text' in data) {
      if (data.text.toLowerCase() == "@pbtest001 start") {
        t.verifyCredentials(function (err, data) {
          console.log(err);
          // console.log(data);
        })
        .updateStatus('pickup started!',
          function (err, data) {
            console.log(err);
            // console.log(data);
          }
        );
      }
    }
  });
  stream.on('end', function (response) {
    // Handle a disconnection
  });
  stream.on('destroy', function (response) {
    // Handle a 'silent' disconnection from Twitter, no end/error event fired
  });
});

And the error returned from updateStatus:

{ [Error: HTTP Error 401: Unauthorized, API message: {"errors":[{"message":"Coul
d not authenticate you","code":32}]}]
  data: '{"errors":[{"message":"Could not authenticate you","code":32}]}',
  statusCode: 401 }

I'm getting this error as well... and on DMs

This is a bug in the oauth dependency - as I understand it, it's already fixed upstream. I'll look into it and release a fixed version ASAP.

I was having the same problem and found that having characters like exclamation points and apostrophes in the message was the problem.

As mentioned, the issue seems to be upstream in node-oauth, where these characters are not being properly escaped. See ciaranj/node-oauth#113 (comment) and ciaranj/node-oauth#114 for a better description and some possible solutions.

Thanks @AvianFlu for looking into this.

Does it escape correctly in 0.4.1?

0.4.1 uses the old Twitter REST API (v0.4.1...v0.5.0#L1R7), which seems to be a little more forgiving to unescaped characters.

Any resolution?

I had the same situation testing my library. I think the problem is related with the app credentials. Try creating a new app if you are using the REST API V1.1.

Having the same issue. Reverted to v0.4.1 as temporary solution.

Is there any update on this? One of my applications is quite seriously affected by this bug.

yep @guyht
[quote @tylor] As mentioned, the issue seems to be upstream in node-oauth, where these characters are not being properly escaped. See ciaranj/node-oauth#113 and ciaranj/node-oauth#114 for a better description and some possible solutions.

So you just need to replace this code:
rolandboon/node-oauth@240a992

or this:
https://github.com/jamescauwelier/ntwitter/commit/0756426e60c44d1a9de19c5a96e0de078926a114

:)

Thanks @preziusoftware

The node-oauth patch rolandboon/node-oauth@240a992 solved the issue.

:) you most welcome

This also applies with the twitter stream

streamFilter = { track: 'that\'s cool' };
twitter.stream('statuses/filter', streamFilter, function handleStream(stream) {
    stream.on('error', function(err, data){
        console.log(err);
        console.log(data);
    });
})

It returns a 401 error

Everyone, I applied the patch mentioned by @kaosdynamics and it worked perfectly.

Looks like the issue is now fixed in node-oauth ciaranj/node-oauth@45a983e Hopefully we'll have an updated npm package soon.

+2 plz