Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user's twitter stream using node.js twit?

I'm using the node.js Twit module; after the user has authenticated, how do I get that user's tweets? The documentation does not explain how to do it.

The following returns null:

var Twit=require('twit');
var T = new Twit({
  consumer_key:         nconf.get('twitterAuth:consumerKey')
, consumer_secret:      nconf.get('twitterAuth:consumerSecret')
, access_token:         user.token
, access_token_secret:  user.tokenSecret
});
var username=user.profile.username;

T.get('search/tweets', {screen_name: username, count:100  }, function(err, data, response) {
  //q: 'banana since:2011-11-11', count: 100
  res.send(data);
})

Thanks for any help - must be something obvious. (I have confirmed the code works).

like image 272
metalaureate Avatar asked Oct 22 '14 02:10

metalaureate


People also ask

How do you get a live tweet on Twitter?

Tap Live at the bottom selector. Fill in an optional description that will appear as a Tweet, and a location if desired. Tap Go live. Your live broadcast, with description and location (if added), will appear in a Tweet in your followers' timelines and on your profile.

How do I make a Twitter stream?

In the left sidebar menu, under Twitter Streams, click Create stream. Set up your new Twitter stream: Stream name: enter a name for your Twitter stream. Show me tweets from: select an option for whose tweets you can monitor.


1 Answers

You've probably already solved your problem, but for anyone else out there that's struggling with this, here is my solution:

var Twit = require('twit');

var T = new Twit({
    consumer_key:         ''
  , consumer_secret:      ''
  , access_token:         ''
  , access_token_secret:  ''
})

var options = { screen_name: 'sandagolcea',
                count: 3 };

T.get('statuses/user_timeline', options , function(err, data) {
  for (var i = 0; i < data.length ; i++) {
    console.log(data[i].text);
  }
})

This shows my last 3 tweets :) Cheers!

like image 115
Sanda Avatar answered Sep 17 '22 22:09

Sanda