Muschamp Rd

RSS Feed from Twitter Search with PHP

March 4th, 2013
Twitter logo

Twitter is removing support for RSS feeds in a few days. If you actually used the RSS feed feature of the original Twitter API this is disappointing. Twitter wants to know who is making every single request to their API whereas RSS is fairly anonymous. I was also using Topsy to search Twitter and then I subscribed to an RSS feed of those results. This is one of the techniques I used when I built my custom news aggregator.

Topsy now wants you to pay to use their API including their RSS feeds. Twitter’s API is still free to use, but all your RSS feeds will stop working on March 5th, aka tomorrow. So after my interruption to answer random math questions, I finished my quick and dirty RSS feed for a keyword search on Twitter using version 1.1 of their API.

Not Twitter Approved Workaround

Since Twitter is removing official RSS feeds they might not be amused that I hacked out a workaround this morning and am posting it to my blog, but if I had a job I wouldn’t have so much time on my hands. I don’t even like PHP.

This hasn’t been exhaustively tested. It doesn’t support every search option in version 1.1 of the Twitter API. It does produce a valid RSS feed for a simple keyword search such as “Vancouver”. Quotation marks are not necessary. I’m going to polish it a bit more but here is the minimal viable solution for turning search results from Twitter into an RSS feed.

I use CodeBird and the same basic technique to search Twitter as before, I then used the same basic technique I used with SimplePie to make the RSS feed. I used some sort of standard PHP method of passing a variable to a URL aka php?q=searchterm and currently I don’t do a lot of validation or beautifying or ensure that for all possible tweets that I produce valid XML.

Still haven’t violated Twitter’s Terms of Service

I don’t think this violates Twitter’s terms of service, but you are supposed to meet the display requirements which you can not do with just the contents of the RSS feed. Of course if you just want to subscribe to the RSS feed in your newsreader or something else you’ve coded up to monitor keywords this code is the basis of a workaround.

PHP code produces valid RSS feed

It is now several years later and this code is still running on my website and although other APIs may be blocking or throttling me or just plain have stopped working this technique still works in 2019. I’m once again looking for a job and this time I plan to leverage my coding ability and this blog more. If you have any thoughts on PHP, JavaScript, Twitter, or RSS you can leave them below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.