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.

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 for all possible tweets that I produce valid XML.

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


Posts on Muskblog © Andrew "Muskie" McKay comments not necessarily so...
Social Media Icons created by komodomomedia, used with permission.