Tweetledee is a MIT licensed PHP project on GitHub that simplifies access to Twitter JSON and RSS feed data for user timelines, home timelines, lists, favorites, and tweet search. You can run the PHP files directly through the PHP interpreter using standard CLI syntax, take advantage of the many available options through command line switches, and pipe the Twitter data to any application that you’d like. Here’s how you do it.
- Resource: Tweetledee
- Docs: Tweetledee documentation
- Dependencies: PHP 5.3+ for RSS + JSON, PHP 5.4+ for pretty printed JSON
How to Run Tweetledee from the Command Line
You can access Twitter JSON and RSS feed data through the Tweetledee files with standard command line syntax and display your results in a terminal or pipe the data through the standard out stream to any other application. Instead of running the Tweetledee scripts via URL on a web server, you run the them directly through the PHP interpreter. The Tweetledee files automatically detect whether you are accessing the data by URL or from a terminal window.
The Tweetledee scripts have a number of available options that allow you to modify the user of interest, exclude retweets or replies, define your search query and more. These parameter names do not change with the CLI approach; however, you use standard CLI syntax to define them. For single character options, use a short switch format (
-c). For multiple character options, use a long switch format (
Here are a few examples. Download the Tweetledee files from the GitHub site, navigate to the inner tweetledee directory and then test the following commands that demonstrate the options available for the user timeline JSON file.
User Timeline JSON (default user = you)
User Timeline JSON (another user = me)
User Timeline JSON (another user + exclude RT’s)
User Timeline JSON (another user + exclude RT’s + include only 5 tweets)
Pipe the Twitter Data to Another Application
Viewing the data in your terminal is not terribly exciting. The beauty of this approach is that the JSON data travels through the standard out stream when you run a Tweetledee script directly through the PHP interpreter so you can pipe it to any application that accepts data through the standard in stream. This provides an easily implemented Twitter JSON (or Atom feed) data source for any application without the hassle of generating the OAuth code yourself.
As a trivial, relatively useless demonstration of the approach, let’s pipe the user timeline JSON to the *nix application wc to perform a character count.
Twitter User JSON Data Piped to wc for a Character Count
Simple. I leave it as an exercise for the interested reader to come up with a much more useful application of your Twitter data.