Basic Twitter API Example Scripts in Ruby, Python, and Perl

I've been playing with Twitter's REST API to collect stats for work. Data like: follower counts, what Tweets are being faved, etc... There are libraries for working with the API, but no good examples for using it directly. So, I wrote my own^1^^.

It's not super complicated, but there are some tricky parts. I'm posting my code here for posterity's sake.

Each example follows the same basic flow outlined in Twitter's Application-only Authentication approach.

Step 5 being where real work would actually happen. It's also where looping for to make additional API requests would take place since the Access Token only needs to be pulled once^2^^.

Here's the code:

Ruby

Python

Perl

A few things to keep in mind with these examples:

Generally, I'm all for using code libraries to make life easier. Working with APIs is a different story. Unless whoever makes the API is also providing the library, I'd rather use the service directly. Avoiding third-party dependencies is well worth the little extra work it takes. And, if there are good examples available there's not a huge difference between the levels of effort.