ttezel / twit

Twitter API Client for node (REST & Streaming API)
4.32k stars 573 forks source link

Unable to stream tweets based on username or user id #539

Open a-ferraro007 opened 3 years ago

a-ferraro007 commented 3 years ago

I'm trying to stream tweets from a specific user so i can be notified every time that user tweets. Whenever i stream with the like { track: 'from:carmeloanthony' } it never returns any tweets. went through the twitter docs and from: is a valid track filter a stream.

full code

    let stream = T.stream('statuses/filter', {track:'from:carmeloanthony'})
    stream.on('tweet',  (tweet) => {
      console.log(tweet) 
      }
AditModi commented 3 years ago

var stream = T.stream('statuses/filter', { follow: twitter_config.handles , track: twitter_config.topics , language: twitter_config.languages });

I tried using follow for tweets from a specific username/user-id . I am also encountering some issue, if anyone has an answer do let us know.

maziyarpanahi commented 3 years ago

I don't believe you can use from: in track. That must be a new API which this library doesn't support.

If you use UserID in the follow it works:

let stream = T.stream('statuses/filter', {follow:'25073877'})
    stream.on('tweet',  (tweet) => {
      console.log(tweet) 
      }
follow?: boolean | string | string[];
AditModi commented 3 years ago

@maziyarpanahi , why does this not work??

var stream = T.stream('statuses/filter', { follow: twitter_config.handles , track: twitter_config.topics , language: twitter_config.languages });

maziyarpanahi commented 3 years ago

What's inside those configs? Also, what's the error?

AditModi commented 3 years ago

@maziyarpanahi, I am using above approach but it doesn't seem to work. twitter_config.handles are the user-ids and topics are the keywords.

is user-ids correct way of referencing for this architecture???

Should I be using screen_name or user-id???

What to do if i have to use few thousand user-ids and a few keywords??

What about using the same-ip address for entire twitter-scraping application???

Also the approach is used to scrap the twitter data based on handle value and keyword but scraping itself doesn't work.

maziyarpanahi commented 3 years ago

I asked cause I wanted to be sure the type is correct. They have to be array of strings. You need to look into the limit of this API for your questions but it supports up to 5000 user ids and 400 keywords. My suggestion is to just manually add a popular userId and popular keywords as array [] and test that. Like run this code, nothing more or less:

let stream = T.stream('statuses/filter', {follow:'25073877'}) stream.on('tweet', (tweet) => { console.log(tweet) }

If this works then you either have type error in your lists or they are more than the limits. (Listen to the errors, they come with code which you can search in Twitter, you might be blocked or have more stuff than you should etc.)

The code above works and it works if you have lists of userIds and keywords less than the limits. (Find the errors and follow up from there)

Best of luck

AditModi commented 3 years ago

@maziyarpanahi ,

ar Twit = require('twit'); var util = require('util');

var config =require('./config');

var T = new Twit(config) var stream = T.stream('statuses/filter', { follow: ['56488059','2227355222'] , track: ['Covid','Corona'] , language: ['en'] });

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

The above approach works but not as i want.

it is an OR relationship. You will receive a Status object whether the keyword was present or the user id was involved (this includes other users tweeting to your followed user id).

How can I ensure that for those particular user_ids only , I get the keywords used . ( ensure AND relationship between user_id and keyword )