Recieve real-time updates to user timeline


#1

Hi!
Is it possible to use the twitter api to recieve real-time updates of a user timeline? If so, what would be the best way?

Sorry if this isn’t the correct subforum.
Thanks!


#2

Sure, best one to use is https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter with the follow parameter


#3

Thanks!
A couple of follow up questions:

  1. Will this really send updates when the user’s timeline updates due to a tweet from another user he is following?
  2. Is there any limit to the amount of users you can apply this to?
  3. Is it free?

#4

Oh, i thought you meant user timeline as in 1 specific user’s tweets like a streaming equivalent of https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline , not tweets by anyone a specific user is following like https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline

In both cases though, the filter endpoint is what you’ll need - it’s free and there’s a 5000 id limit on the number of users you can track, and you can keep open 1 such connection. You can get user ids of accounts someone is following with https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids


#5

Thanks, I’ll give it a try!

Btw, I was looking into webhooks(https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/guides/getting-started-with-webhooks.html) earlier. Do you know if I can get updates when a user’s timeline is updated (due to his friend’s tweets) from that? I thought so at first but I’m unsure now.


#6

Not for any tweet, but partially yes: https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/guides/account-activity-data-objects here’s stuff you get from Activities API - so whenever a someone Retweets, Replies, @mentions, QuoteTweets you, you’ll be able to get those messages, but not when anyone you follow makes any kind of tweet - just one that includes you.


#7

What you’re describing and requesting is real-time updates to what we call a user’s “home timeline” i.e. all of the Tweets the user would see if they opened twitter.com and looked at the stuff flowing in from the people they follow. This is no available in the API, but you can approximate it. You can also poll the RESTful home_timeline endpoint, but this is not realtime.


#8

Thanks Igor! you saved me a lot of time. I’ll look into the filter realtime feature :slight_smile:


#9

Ok thanks! Yeah I have tried polling it but I’d prefer realtime.


#10

@anders811 lets buy Enterprise powertrack on 50:50 partnership
i also need to get tweets from 10k or more twitter accounts in realtime .


#11

Thx for the offer, but 5k is enough for me :slight_smile:


#12

Hi again!
I haven’t had much time to look into this and just now started a bit.
Maybe you can help me with a few questions :slight_smile:

  1. Do you have any suggestions on http client libraries for php that work with “filter real-time tweets”? Guzzle maybe?
  2. Is there any difference between https://developer.twitter.com/en/docs/tweets/filter-realtime/overview and https://developer.twitter.com/en/docs/tutorials/consuming-streaming-data.html? The latter seem Enterprise-only so I’m a bit confused.
  3. I noticed these libraries: https://github.com/spatie/twitter-streaming-api & https://github.com/fennb/phirehose. I’m confused as to which api of the ones above (in question 2) that they work with. I don’t feel like paying for Enterprise after all.
  4. Do you know if there are any php examples for connecting to & using the Filter Realtime Tweets Api?

Sorry if these questions seem strange. I’m very new to all this.
Cheers


#13

I don’t know enough about PHP to say which libraries are good nowadays - there’s a list here https://developer.twitter.com/en/docs/developer-utilities/twitter-libraries.html - but https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html is the endpoint you want, the other documentation link is for enterprise like you said.


#14

Thanks again Igor!
Sorry if my answers are often late like this one. I seldom get the time to sit down and play around with this.

I came across this post just now: https://medium.com/@jainakansha/read-this-before-you-start-developing-using-twitter-data-3d14bdb87cfe which says that the twitter streaming api only returns around 1% of the tweets. Is it the same for https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html? I.e. even if I set my filter parameters quite narrowly it will still only return about 1% of the tweets that match my filter parameters?

Cheers


#16

The sample stream returns roughly 1% of all tweets on twitter (it’s not exactly 1% but it’s close to it) https://developer.twitter.com/en/docs/tweets/sample-realtime/api-reference/get-statuses-sample

The filter stream https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html delivers real-time tweets that match some query

Filter stream will deliver all tweets that match your query, but if the number of tweets that match your query is too large (too large generally means it’s more than the number of tweets in the sample stream), you will start getting limit notices in the stream messages. This is how you know that you are no longer getting all the tweets that match your query.

Hope that helps!


#17

Pheew! :slight_smile:
Thanks again Igor! You’re the best.


closed #18