desmondmorris / node-twitter

Client library for the Twitter REST and Streaming API's.
https://www.npmjs.com/package/twitter
MIT License
1.27k stars 237 forks source link

Error message (code 89): Invalid or expired token #237

Closed jtiscione closed 7 years ago

jtiscione commented 7 years ago

I'm trying the very first example in README.md:

var Twitter = require('twitter');
var credentials = require(__dirname+"/credentials.json");

var client = new Twitter(credentials);

var params = {screen_name: 'nodejs'};
client.get('statuses/user_timeline', params, function (error, tweets, response) {
    if (!error) {
        console.log(tweets);
    } else {
        console.error(error);
    }
});

I'm getting this error:

[ { code: 89, message: 'Invalid or expired token.' } ]

None of the other endpoints work either. This is a bug in this module, not any sort of issue with my API key. If I change the first line to

var Twitter = require('twit')

and use the "twit" module instead, everything works perfectly.

JulienSol commented 7 years ago

Hello, what is inside your credentials.json ? Twit and Twitter packages doesn't have same keys options. Twit package keys options:

  consumer_key: '',
  consumer_secret: '',
  access_token: '',
  access_token_secret: ''

Twitter package keys options:

  consumer_key: '',
  consumer_secret: '',
  access_token_key: '',
  access_token_secret: ''
jtiscione commented 7 years ago

Ah, that was it! Thanks!