Web API

The New York Times web site provides a rich set of APIs, as described here: http://developer.nytimes.com/docs You’ll need to start by signing up for an API key. Your task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it to an R dataframe.


INDEX (Step by Step)

STEP 1. Setup the API key
STEP 2. Load the libraries
STEP 3. Read the data
STEP 4. Convert the data into usable dataframe

STEP 0 : Cleanup the Environment

STEP 1 : Set up the API Keys

New York times API can be registered to at http://developer.nytimes.com/signup

STEP 2 : Load your libraries

# Load the libraries
library("httr")
library("rjson")
library("DT")

STEP 3. Read the data

api.key <- "0bed27e078464cd595721a8cd5243dd5"
url <- "http://api.nytimes.com/svc/topstories/v1/home.json?api-key="

result <- GET(paste(url, api.key, sep=""))

STEP 4. Convert the data into usable dataframe

url.content <- content(result)
## No encoding supplied: defaulting to UTF-8.
content.list <- fromJSON(url.content)
content.df <- as.data.frame(do.call(rbind, content.list$results))
colnames(content.df)
##  [1] "section"             "subsection"          "title"              
##  [4] "abstract"            "url"                 "byline"             
##  [7] "item_type"           "updated_date"        "created_date"       
## [10] "published_date"      "material_type_facet" "kicker"             
## [13] "des_facet"           "org_facet"           "per_facet"          
## [16] "geo_facet"           "multimedia"
datatable(content.df)