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

user streaming #234

Closed DusterTheFirst closed 7 years ago

DusterTheFirst commented 7 years ago

how would I use the streaming API to detect when a user posts,

I have

Twitter.stream('statuses/filter', { track: '@dusterthesecond' }, function (stream) {
    stream.on('data', function (tweet) {
        console.log(tweet.text);
    });

    stream.on('error', function (error) {
        console.log(error);
    });
});

but that only tracks tweets that mention @dusterthesecond

JulienSol commented 7 years ago

Hi,

The documentation allow you to pass a follow param.

The stream will then contain :

  • Tweets created by the user.
  • Tweets which are retweeted by the user.
  • Replies to any Tweet created by the user.
  • Retweets of any Tweet created by the user.
  • Manual replies, created without pressing a reply button (e.g. “@twitterapi I agree”).

The stream will not contain:

  • Tweets mentioning the user (e.g. “Hello @twitterapi!”).
  • Manual Retweets created without pressing a Retweet button (e.g. “RT @twitterapi The API is great”).
  • Tweets by protected users.

I think you can try this :

let user_id = 3657556095; // @dusterthesecond
Twitter.stream('statuses/filter', { follow: user_id }, (stream) => {
    stream.on('data', (tweet) => {
        console.log(tweet.text);
    });

    stream.on('error', (error) => {
        console.log(error);
    });
});

If you only want :

  • Tweets created by the user.
  • Tweets which are retweeted by the user.
  • Replies to any Tweet created by the user.
  • Retweets of any Tweet created by the user.
  • Manual replies, created without pressing a reply button (e.g. “@twitterapi I agree”).
let user_id = 3657556095; // @dusterthesecond
Twitter.stream('statuses/filter', { follow: user_id }, (stream) => {
    stream.on('data', (tweet) => {
        if(tweet.user.id === user_id) { // Only tweets from the user id
            console.log(tweet.text);
        }
    });

    stream.on('error', (error) => {
        console.log(error);
    });
});
DusterTheFirst commented 7 years ago

can I make it follow multiple twitters?

EDIT: yes, seperate by commas