Code: TwitterProxy

TwitterProxy allows you to get your Twitter feed (all of your own updates) and then filter them through a series of operations to enhance/modify the feed before doing something else with it. It comes pre-packaged with a number of useful filters such as:

  • Remove updates that look like they’re a reply to someone else
  • Create links on Twitter user names, hashtags  and URLs
  • Remove updates that contain certain words

You can easily add your own filters/functions to do whatever you want to your feed as well. I use TwitterProxy to create a modified feed of my Twitter updates for the mini-lifestream in the sidebar.

Download   TwitterProxy 1.0 (2.6 KiB, 2,362 hits)

Requirements

  • Requires PHP (with the cURL extension installed) and,
  • Will need write access to create a cache file on your server
  • You’ll probably want to know a little bit about query-strings and things like that to use it, and about PHP coding to modify/extend it.

Installation/Configuration

  1. Unzip the file to your server somewhere (it’s a single PHP script, called “TwitterProxy.php”.
  2. Open the file in your favorite text editor and enter your Twitter.com username and password as indicated.
  3. Change “TWITTER_CACHE_FILE” if you like, but make sure that the web server (or whatever is executing the script) has write permissions to the file you specify. The default is a file called “twitter.xml” in the same directory as you placed TwitterProxy.php
  4. Change “TWITTER_CACHE_TTL” to the number of seconds you want to wait between updating your status feed. You can set it to whatever you want, but if you set it lower than 300 you’ll risk being blocked by Twitter’s API.
  5. Construct a request URL representing the filters you want to apply to your feed and then use it whereever you want your modified feed to appear.

Examples

These examples all use functionality/filters that come packaged with the script.

Get rid of updates that appear to be a reply to someone else (if the first thing in the update is “@something”) and add links to anything that looks like a hashtag (#something):

http://server.com/TwitterProxy.php?strip_replies=true&hastags=true

Add links to other people mentioned in updates, but don’t include any updates that include the word “work”:

http://server.com/TwitterProxy.php?link_people=true&stopwords=work

Create links on things that look like URLs, and replace all mentions of “hate” with “love”:

http://server.com/TwitterProxy.php?create_links=true&str_replace=love|hate

Warning: The order that you specify filters in is important. So for example if you want to create links and do a string replacement, you probably want to do the string replacement first (but it will still potentially affect URLs encountered).