Week9 Assignment (Web APIs)

(1) 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.
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(jsonlite)
(2) Get all the books available. Read the JSON data into R data frame.
url1 = "http://api.nytimes.com/svc/books/v3/lists/names.json?"
key1 = "api-key=c991ccaa513642319cd329b0edde7749"
fullUrl1 = paste0(url1, key1)
booksInfo_data = fromJSON(fullUrl1)
booksInfo_df = data.frame(booksInfo_data$results)
colnames(booksInfo_df) = c("List Name", "Display Name", "Encoded List Name", "Published Date (Oldest)", "Published Date (Newest)", "Updated")
class(booksInfo_df)
## [1] "data.frame"
head(booksInfo_df, 10)
##                               List Name                       Display Name                    Encoded List Name Published Date (Oldest) Published Date (Newest) Updated
## 1     Combined Print and E-Book Fiction    Combined Print & E-Book Fiction    combined-print-and-e-book-fiction              2011-02-13              2016-11-06  WEEKLY
## 2  Combined Print and E-Book Nonfiction Combined Print & E-Book Nonfiction combined-print-and-e-book-nonfiction              2011-02-13              2016-11-06  WEEKLY
## 3                     Hardcover Fiction                  Hardcover Fiction                    hardcover-fiction              2008-06-08              2016-11-06  WEEKLY
## 4                  Hardcover Nonfiction               Hardcover Nonfiction                 hardcover-nonfiction              2008-06-08              2016-11-06  WEEKLY
## 5               Trade Fiction Paperback            Paperback Trade Fiction              trade-fiction-paperback              2008-06-08              2016-11-06  WEEKLY
## 6                 Mass Market Paperback      Paperback Mass-Market Fiction                mass-market-paperback              2008-06-08              2016-11-06  WEEKLY
## 7                  Paperback Nonfiction               Paperback Nonfiction                 paperback-nonfiction              2008-06-08              2016-11-06  WEEKLY
## 8                        E-Book Fiction                     E-Book Fiction                       e-book-fiction              2011-02-13              2016-11-06  WEEKLY
## 9                     E-Book Nonfiction                  E-Book Nonfiction                    e-book-nonfiction              2011-02-13              2016-11-06  WEEKLY
## 10                     Hardcover Advice           Hardcover Advice & Misc.                     hardcover-advice              2008-06-08              2013-04-21  WEEKLY
nrow(booksInfo_df)
## [1] 53