TweetPull for RSS

Create an RSS feed of a selected Twitter user's recent tweets using the v1.1 API.


Contributors: sahearn
Tags: Twitter, tweet, API, RSS


Questions/Comments: sahearn at gmail dot com


Description

Background

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.

What You'll Need

Approach

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.


Download

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.


Installation

General

  1. Download tmhOAuth library
  2. Download latest version of TweetPull for RSS package tweetpull.zip above
  3. Open tweetpull-config.php config file and set the following required parameters (descriptions for each appear in config file):
  4. Review and set the optional parameters in the tweetpull-config.php config file

Usage

  1. Follow Installation steps above
  2. Run the script (typically by cron) with the following:

    5 * * * * php /full/path/to/tweetpull.php -u [twitter screen name] [-r] [-t]

    -r is an optional parameter. If it is set, replies are removed from the returned timeline. See statuses/user_timeline for more info.
    -t is an optional parameter. If it is set, retweets are removed from the returned timeline. See statuses/user_timeline for more info.
     
  3. Output file(s) will be [twitter screen name].xml. Enter that file (with full URL) into your favorite RSS reader. (e.g. http://www.mydomain.com/feeds/[twitter screen name].xml)

Changelog

0.4

0.3.1 [download]

0.3 [download]

0.2.1 [download]

0.2 [download]

0.1 [download]


To-do List


Updated: 12 Jun 2014


By the way...

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.