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"