As I saw in v1.1 docs there isn't api for this. What is the painless way to get post or get http request to my webserver when someone posts a tweet? Beside me creating 5 min cron checking users timeline for new tweet. I am using php.
2 Answers
I handled that by using an RSS feed class (SimplePie) to fetch the tweets from Twitter (Twitter provides RSS URLs for each member).
My script loads the tweets into the database. If the latest database entry is older than a certain limit, then a new feed request is made. I did it that way so that I wasn't making too many feed requests. For instance, if you have ten people accessing the page at the same time, it doesn't make sense to overload Twitter with ten RSS feed requests at the same time.
On the page that shows the tweets, I made an AJAX function that sends requests to the server periodically (using setInterval()
) to see if there is anything new.
It turned out to be a pretty complex project, so it's much easier to use the widgets that Twitter provides.
UPDATE:
I just found that as off last month, I believe it was June 12, 2013, Twitter closed down the RSS feed API, so that option is not longer available. There seems to be some workarounds, but the most reliable solution is to just use the widgets that Twitter provides.

- 7,771
- 5
- 30
- 43
-
Thanks for reply. I need it all done by server side, you are running this ajax in browser. – S S Jul 14 '13 at 13:42
-
@SS - I just discovered that RSS feeds are no longer available for Twitter, so I updated my answer. – Expedito Jul 14 '13 at 14:41
-
No, a loop checking for the new tweet every x number of minutes seems like the best solution - crons were made for this sort of thing.
Because RSS is removed and the only response format returned via the twitter API is now json, you're going to be looking at utilising server-side authenticated requests for json only.
If I were in your position, I would do the following:
- Write a script to return as little, but focussed data as possible.
So you're going to be utilising the from:
field in your request to specify the user you want to be checking, and also the count
variable as 1
. This means that you're asking for as little data as possible and you will only have one tweet in the json response to contend with. Use the search/tweets endpoint. Example: ?q=from:username&count=1
.
- Store the last tweet to compare against, and if the one you just retrieved is different, display it / do whatever you want with it.
Now you can either store the tweet in a database (additional overhead) or a flat text file (shouldn't be a problem, the tweet is in the public domin anyway). Alternatively, return the last two tweets, and if they differ, display the latest - only works if they're not tweeting twice, really quickly.
You're going to need a simple library to make authenticated requests. I recommend checking out this post for doing it in PHP, it explains everything and is as little code as possible really. Here's the library.
Finally, I don't know if this will help, but I stumbled upon twoti that claims to e-mail you when a tweet is found. I'm guessing that, really, this'll have a similar architecture to the one I just described, but the service offloads your data retrieval onto their server, so you could do something different by checking an e-mail address (that may have the 'push' notification you require) for the new tweets. Good luck!