Create an RSS feed of a selected Twitter user's recent tweets using the v1.1 API.
Tags: Twitter, tweet, API, RSS
Questions/Comments: sahearn at gmail dot com
For some time, Twitter RSS-enabled a user's stream, meaning one could essentially follow a user without interacting with the Twitter front-end website (or app). This allowed one to add one of two specifically-crafted URLs into their RSS reader of choice:
http://twitter.com/statuses/user_timeline/[numeric twitter id].rss , or
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=[twitter screen name]
This was great for people like me who are devoted to RSS, want to follow people on Twitter, but generally hate sifting through the streaming mess of the Twitter site. However, in the summer of 2013, Twitter officially deprecated v1 of its API, and released v1.1; and with it, they removed the ability to make un-authenticated requests to the API. This effectively killed any ability to quickly and easily pull recent tweets via a simple URL.
Since the v1.1 API allows authenticated requests to a large number of very useful methods, the first step was to sign in to the Twitter Developer site and create an application that would authenticate back to me. This is done via creation of "consumer keys" and "access tokens" that are unique to the developer and are placed in the request header.
The next step was to find a way to create a valid request header with my keys/credentials along with my desired get method (in my case, statuses/user_timeline). GitHub user themattharris made all the authentication portion incredibly easy by developing an OAuth library written in PHP.
Once the request was formed, my code was then a matter of extracting the JSON response, parsing the user's tweets, and dropping them to a well-formed RSS/XML file. This might seem like an involved and somewhat unnecessary approach, but my primary reasoning was due to Twitter's API rate limiting. Read that, and the following "gotchas" should make more sense:
In general, a lot of improvements can be made here, but it's good enough for a v0.1 release. And I only did it because the v1.1 API is so new, I couldn't find anyone else doing something similar yet.
Latest: v0.4 (Apr 2014) - tweetpull.zip
View source: tweetpull.php
View config: tweetpull-config.php
License: This script is released under the Apache v2.0 License. Please note the tmhOAuth library is also published under Apache v2.0. Please use accordingly.
Updated: 12 Jun 2014
I recently realized that Instagram does not have open, available RSS feeds, either. Like Twitter, Instagram has provided a developer API. But unlike Twitter, Instagram's API is confusing to set up and very poorly documented. Regardless, the community has responded. The folks over at web.stagram.com created a utility to pull feeds from public Instagram users. If the user has made their feed private, though, you need to host your own solution. I was able to come up with a quick script based roughly off of TweetPull. It's an 0.1 release - very dirty and not as polished.
Note: the single input (-u [userid]) is not the Instagram's user screen name, but rather their numeric ID; go to their page, view source, and search for "id" in the big JSON block.