As more and more journalists are finding, APIs are a great way to get data for your Web applications and projects.
An API, or application programming interface, enables software programs to communicate with one another. (Chrys Wu wrote a helpful intro here.) To give you a better understanding of how they can help you, I’ve outlined some of the best APIs for finding content and explained how you can use open-source programming tools to glean information from them.
Twitter’s API is very well documented and has a lot of useful functionality. It’s especially useful for journalists who want to search Twitter for a term and either show or parse the results. Let’s take a look at how we can easily do that.
Here is some simple example code that searches Twitter for the term “earthquake” and then creates a bulleted list for the tweets that are found. You can copy and paste the code and replace the word “earthquake” with whatever term you want to search for.
If your development team uses open-source tools, there are some great libraries for parsing the Twitter API with much more advanced functionality than the snippet above. For PHP, use TwitterOAuth. For Python, use Tweepy. For Ruby, use Grackle.
Google Maps API
Google Maps has an extensive API with many different features. You can use it to build maps, geolocate tweets (or other pieces of data with latitude and longitude variables), search for local schools, or even measure elevation or distance. The API has a lot of documentation with several examples. Depending on what you’re trying to do, you can find code snippets to help you achieve your goal.
Here are a few good examples from the documentation:
- Follow the Google Maps “Hello World” tutorial to see how easy it is to get a map up and running.
- Use the Google Places API to track information such as the density of schools in different neighborhoods.
- Build a Twitter location application using the Google Geocoding API.
There are also numerous wrappers for the Google Maps API in PHP, Python and Ruby, so consider reaching out to your development team for advice on how to integrate Google Maps with the apps they’re already building.
The Facebook Graph API is JSON-enabled and has search functionality similar to Twitter. You can search for who is posting publicly about topics, search Facebook Places, and see photos and videos posted publicly or by your page’s followers.
Facebook has a fairly extensive section of code examples that you can use and tweak to your liking. Some highlights are:
- The ability to create a feed of your friend’s likes.
- The ability to show photos of your friends who like a particular story or article.
- An API Explorer, which enables you to see relationships between graph data and gather information for your beat or a particular story.
Other noteworthy APIs
The folks at Participatory Politics and Sunlight Labs have built a series of amazing APIs with access to government data — a notoriously tricky task. They have a new project called Open Government that aims to help users track numerous government data sets pertaining to politicians, bills, campaign donations and voting — all the way down to the local level.
Although they don’t have support for every state yet, Open Government is under active development, so more states will be added over time. The code they’re using is all open-source and built in Ruby.
Experimenting with APIs is just one of many ways to build your skills as a digital journalist. The more you know about the open-source culture, the more you can effectively share data, collaborate with others in the newsroom and, perhaps most importantly, tell innovative stories.