You don’t need to be a software developer or hardcore techie to use APIs. In fact, some web APIs, like the Twitter API, are relatively easy to use, and you can use them get access to useful and otherwise hidden data. When you start looking into APIs, you’ll also see how simple some of those web applications really are when you discover the underlying API calls used to build them.
Before you can start to play with Twitter’s API, you’ll need to know a few API basics. You can find information about constructing URLs, rate limiting, keys and more in my previous post about using APIs. Now, let’s look at a few fun things you can do with Twitter’s API.
Show User Data
The various web applications that do simple things like showing when a user joined Twitter are probably using data from the users/show API call. While most of this data can be found by looking at a user’s profile page, there are a few interesting tidbits that are only in the API, like account creation date (created_at), number of favorites (favourites_count), time zone (time_zone), ID number (id) and more.
In this example, you should replace geekygirldawn with the username that you want to learn more about.
The statuses/friends API call is a fun way to get the data we got using at in the users/show call, but for all of the people a particular user is following. The data is displayed for 100 users at a time with the most recently followed users at the top.
Again, replace geekygirldawn with the username that you want to learn more about.
Unfortunately, it doesn’t seem to have a way to sort by oldest friends first (or at least no documented way in the API) without some additional programming required. However, adding the cursor=-1 option, shown above, does let you page through the results. To get the next page of results, scroll to the bottom of the results to find the next_cursor attribute value, and replace the -1 in the above call with the value found in next_cursor. It should look something like this:
The statuses/followers API call is very similar to the statuses/friends API call, but it returns data about the people who have followed a certain account. It’s an interesting way to get all kinds of relevant data on one page about the people who have recently followed you. Like the statuses/friends call above, the data is displayed for 100 users at a time with the most recently followed users at the top.
Like the other examples, you should replace geekygirldawn with the username that you want to learn about. You can also page through the results using the next_cursor attribute described in the above example.
Important Information You Should Know
- Rate Limiting. Using this technique to get data from the Twitter API results in a limit of 150 calls per IP address per hour, which is fine for most users. However, those of us who work at large corporations where most of the company’s Internet traffic goes out under a single or small number of IP addresses will find ourselves almost immediately rate limited, so doing this from home is probably a better option. Developers get around this by authenticating with the Twitter API, but that’s a little more complicated.
- Viewing XML. Some browsers do a better job than others in displaying XML from the Twitter API in a format easily read by humans. While I use Chrome (s goog) for most of my web browsing, I like to view XML / RSS using Firefox, since it displays a nicely formatted structure for the data. You can also save the XML as a file and view it in your favorite text / code editor.