ntwitter icon indicating copy to clipboard operation
ntwitter copied to clipboard

v0.5.0 updateStatus error

Open twojcik opened this issue 13 years ago • 18 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 ?

twojcik avatar Sep 21 '12 11:09 twojcik

Same error for me, any ideas?

fender avatar Oct 02 '12 02:10 fender

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 }

fender avatar Oct 02 '12 02:10 fender

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

supernayan avatar Oct 03 '12 04:10 supernayan

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.

AvianFlu avatar Oct 03 '12 05:10 AvianFlu

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 https://github.com/ciaranj/node-oauth/issues/113#issuecomment-8761268 and https://github.com/ciaranj/node-oauth/pull/114 for a better description and some possible solutions.

Thanks @AvianFlu for looking into this.

tylor avatar Oct 03 '12 17:10 tylor

Does it escape correctly in 0.4.1?

nayanjain avatar Oct 03 '12 17:10 nayanjain

0.4.1 uses the old Twitter REST API (https://github.com/AvianFlu/ntwitter/compare/v0.4.1...v0.5.0#L1R7), which seems to be a little more forgiving to unescaped characters.

tylor avatar Oct 03 '12 18:10 tylor

Any resolution?

nayanjain avatar Oct 05 '12 02:10 nayanjain

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.

impronunciable avatar Oct 07 '12 00:10 impronunciable

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

brentertz avatar Oct 10 '12 16:10 brentertz

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

guyht avatar Oct 22 '12 16:10 guyht

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: https://github.com/rolandboon/node-oauth/commit/240a992553ade34ce8a3f970d9c1c21eebd6ff85

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

:)

kaosdynamics avatar Oct 22 '12 16:10 kaosdynamics

Thanks @preziusoftware

The node-oauth patch https://github.com/rolandboon/node-oauth/commit/240a992553ade34ce8a3f970d9c1c21eebd6ff85 solved the issue.

nickcheng avatar Oct 23 '12 09:10 nickcheng

:) you most welcome

kaosdynamics avatar Oct 23 '12 12:10 kaosdynamics

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

jedt avatar Nov 28 '12 08:11 jedt

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

jedt avatar Nov 28 '12 08:11 jedt

Looks like the issue is now fixed in node-oauth https://github.com/ciaranj/node-oauth/commit/45a983e6dc059f8283da646bf33dec37a46c4aa3 Hopefully we'll have an updated npm package soon.

heikkiv avatar Nov 28 '12 15:11 heikkiv

+2 plz

jfhbrook avatar Dec 16 '12 12:12 jfhbrook