Activity: 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.

1.Objective: Get the top stories from nytimes into a data frame.

2.Register and get the key for the topstories API API URL: http://api.nytimes.com/svc/topstories/v1/home.[response-format]?api-key={your-api-key}

3.Setup

library("httr")
library("rjson")

4.Get the content

result <- GET("http://api.nytimes.com/svc/topstories/v1/home.json?api-key=3263f9d73ef1b9a1bd4a66174b1e832f:14:71881873")
names(result)
## [1] "url"         "status_code" "headers"     "all_headers" "cookies"    
## [6] "content"     "date"        "times"       "request"
content <- content(result)

5.Transform the content into a data frame

json.list <- fromJSON(content)
json.df <- as.data.frame(do.call(rbind, json.list$results))
colnames(json.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"