GitHub: https://github.com/seung-m1nsong/607
rpubs: https://rpubs.com/seungm1nsong/963987

Assignment

The New York Times web site provides a rich set of APIs, as described here: https://developer.nytimes.com/apis
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 into an R DataFrame.

API

If the user does not have an account, they must first create an account at https://developer.nytimes.com/. After creating an account, you must apply for and receive an API key. I chose the US top story API for this assignment.

url <- "https://api.nytimes.com/svc/topstories/v2/us.json?api-key="
api_key <- "m5dpIvS3G7Y9JxotqgiQPJOQAQlg07j8" #personal API Key
api_path <- paste(url,api_key, sep = "")


Read json data and insert it into R data frame. If you receive JSON-formatted data as HTTP Response, you can easily organize the desired data using the jsonlite package. You just need to convert the HTTP Response object to text and then extract the data in JSON format.

usTop <- as.data.frame(fromJSON(api_path))


Review the data frame.

head(usTop)
colnames(usTop)
##  [1] "status"                      "copyright"                  
##  [3] "section"                     "last_updated"               
##  [5] "num_results"                 "results.section"            
##  [7] "results.subsection"          "results.title"              
##  [9] "results.abstract"            "results.url"                
## [11] "results.uri"                 "results.byline"             
## [13] "results.item_type"           "results.updated_date"       
## [15] "results.created_date"        "results.published_date"     
## [17] "results.material_type_facet" "results.kicker"             
## [19] "results.des_facet"           "results.org_facet"          
## [21] "results.per_facet"           "results.geo_facet"          
## [23] "results.multimedia"          "results.short_url"