Blog

categories

tags

RELATED Posts

API

Stands for Application Programming Interface, a term most commonly used to refer to a set of methods for retrieving information from a web application like Facebook, Twitter, or FourSquare. In many cases, certain types of information can be retrieved by typing specially-formatted requests directly into the URL-bar of a browser window. When the page is loaded on these requests, the information is usually returned as some type of structured text, such as JSON or XML, though the details depend on the specific application.

[expand title=”What is it good for?” trigclass=”contentLink”]
For journalists, APIs can provide a means for doing targeted data mining of social media and other resources. For example, while it’s possible to use Twitter’s Advanced Search page to search for tweets that contain particular hashtags and/or are from particular users, these results are difficult to analyze because they are embedded in a web page. By contrast, using the Twitter Search API will return the data as either XML or JSON, which can be more easily converted to spreadsheet formats like .csv or .xls. More complex uses include embedding live Twitter feeds or searches in a webpage, or allowing users to tweet to their own accounts from a site other than Twitter.com.

[/expand]
[expand title=”What does it look like?” trigclass=”contentLink”]
Using APIs to retrieve information requires building ugly-looking URLs and then pasting them into a URL-bar and loading the webpage. Because every API is different, the details will vary, but companies that provide APIs for their services usually offer some documentation that includes example searches or “queries” to get you started. In general, these queries conform to the following structure:

http://API_domain_URL/data_format?parameter_code=parameter_value&parameter_code=parameter_value

In the case of the Twitter API, an example search might be:

http://search.twitter.com/search.atom?q=%40emilybell+AND+%23ows&until=2011-10-14

Where:
API_domain_URL = search.twitter.com
data_format = search.atom (“atom” is a type of XML)
parameter_code (1) = q (this is short for “query”)
parameter_value (1) = %40emilybell+AND+%23ows
parameter_code (2) = until
parameter_value (2) = 2011-10-14

Note that very often APIs require spaces and certain punctuation in queries to be replaced with special codes, e.g. %40 for “@”, %23 for “#”, or %20 for ” “. This is called URL encoding.

For some examples of API documentation, take a look at the following:

Twitter Search API

Yahoo Finance Stock Quotes API

Google Image Charts API

[/expand]
[expand title=”How do I use it?” trigclass=”contentLink”]
Every API is different; the company (e.g. Twitter, Yahoo, Google) determines how much and what kinds of information an API makes available. Generally, using an API means constructing a query, running it in a browser window, and then downloading the resulting data for analysis. However, some APIs may create code intended to be embedded in a webpage, such as Google Image Charts or Visualizations.

[/expand]
[expand title=”An example” trigclass=”contentLink”]
A good way to get started with an API is to take an example query URL (often referred to as an “API call”) and start changing parts of it to see how it affects the result.

For example, copy and paste the text below into the URL-bar of a new browser window, and load the page:

http://search.twitter.com/search.atom?q=%40emilybell+AND+%23ows

Since %40 is the code for “@” and %23 is the code for “#”, emilybell can be replaced by any other Twitter handle and ows can be replaced by any other hashtag.

To specify only tweets before a certain date, the “until” parameter can be added, making the above query:

http://search.twitter.com/search.atom?q=%40emilybell+AND+%23ows&until=2011-10-14 

The second query is the same as the first, except that it will return only results posted before October 14, 2011. (Note that because the Twitter Search API only stores results for about a week, you may need to alter the above hashtags and dates to see any results.)
[/expand]
[expand title=”Where can I find it?” trigclass=”contentLink”]
A simple web search (such as “Yelp API”) is often the most direct way to find out whether a particular product or service has an API available. Alternatively, the product’s main site may have a section in the footer labeled “API” or “Developers” which may link to an API. Larger products will often have more than one API available, so you may need to read the summary of each one to determine which one best suits your needs.
[/expand]
[expand title=”Issues & FAQs” trigclass=”contentLink”]
No FAQs yet.
[/expand]

[expand title=”Tools & Tutorials” trigclass=”contentLink” expanded=”true”]
Eric Meyer’s URL Encoder-Decoder can be handy for converting the spaces and punctuation in an API call into their appropriate formats.
[/expand]