ttezel / twit

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

[Feature Request] Update documentation about Stream endpoints #398

Open yordis opened 6 years ago

yordis commented 6 years ago

This is probably no your fault, but mine or twitter documentation.

This is the first time dealing with twitter API and I am trying to understand which stream should I use.

Currently you have this.

path

Streaming endpoint to hit. One of:

'statuses/filter'
'statuses/sample'
'statuses/firehose'
'user'
'site'
For a description of each Streaming endpoint, see the Twitter API docs.

and I clicked on the link and sent me to the general documentation. I clicked everywhere play I could and I googled about it but I get no results.

I have no clue which endpoint should I use. Right now I just need to track some users and get the tweets from them. If I use user do not work, and if I use statuses/filter then I get everything about that user instead of just the tweets from it.

Based on my frustration I will super mega appreciate if you explain how those stream path works and when to use each other.

maziyarpanahi commented 6 years ago

Do you mean get the tweets from the users in real-time or going back in the history? One is the Streaming API and the other is the search API. For Streaming API just use follow and the UserID of those users. You will get their tweets, their re-tweets, if someone reply/retweet their tweets, etc. You can filter them after to just keep what is original from the users you are following. Search API is a bit tricky with rate limit, but it is possible with a bit of work. (only up to 3000 recent tweets for each user's feed)

yordis commented 6 years ago

@maziyarpanahi right now I need to understand which path should I use.

And

Indeed I using follow: [userid, ...] but the issue with that is that I am getting the tweets from everyone that tweet about that user as well.

I will need to filter in my end the tweets so I only care about the onces that come from that follow list.

But I will appreciate if you document the path thing because I am not getting which path to use for what.

maziyarpanahi commented 6 years ago

@yordis Unfortunately I don't have write access to this repo so I can just help you here. The only possible way is to use what you are already using statuses/filter and follow userIDs.

Twitter suggests in its documentations to filter post stream. Situations like filtering by keywords and Geo at the same time and not knowing if the incoming tweet is coming for which keywords or which geo box.

What I would do is to simply use a find function to see if user.id_str of the original incoming tweet is in your userIDs array. Then you can keep or discard it.

PlanetVaster commented 6 years ago

I know that this question is old, but for future reference it returns all tweets from the users AND replies to their tweets. You have to filter for only their tweets. var stream = T.stream('statuses/filter', { follow: userID }); stream.on('tweet', function (tweet) { if (tweet.user.id == userID) { console.log(userID + "tweeted: " + tweet.text); } });

maziyarpanahi commented 6 years ago

I update my own answer that suggests to check the user id

This is not a good way if you tracking multiple users. I guess you can still do a lookup inside the array of UserIDs, but if all you care is the original tweets created by the users you are tracking you should do this: Tweet should not have these objects:

retweeted_status (this is a retweeted tweet) quoted_status (this is a quoted tweet)

And Tweet in_reply_to_user_id must be null.

After having these 3 conditions, anything inside your if will be original tweets only created by the users you are tracking not any interactions by other users.