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
library(httr)
library(dplyr)
library(jsonlite)
library(kableExtra)
Get list of all NY Times best sellers list
lists <- "https://api.nytimes.com/svc/books/v3/lists/names.json"
nyturl <- paste(lists, api_key, sep = "")
nyt <- GET(nyturl)
jsonnyt <- fromJSON(content(nyt, "text"))
NYTBestSellerList <- jsonnyt$results
NYTBestSellerList %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed"), fixed_thead = T)
| list_name | display_name | list_name_encoded | oldest_published_date | newest_published_date | updated |
|---|---|---|---|---|---|
| Combined Print and E-Book Fiction | Combined Print & E-Book Fiction | combined-print-and-e-book-fiction | 2011-02-13 | 2019-11-03 | WEEKLY |
| Combined Print and E-Book Nonfiction | Combined Print & E-Book Nonfiction | combined-print-and-e-book-nonfiction | 2011-02-13 | 2019-11-03 | WEEKLY |
| Hardcover Fiction | Hardcover Fiction | hardcover-fiction | 2008-06-08 | 2019-11-03 | WEEKLY |
| Hardcover Nonfiction | Hardcover Nonfiction | hardcover-nonfiction | 2008-06-08 | 2019-11-03 | WEEKLY |
| Trade Fiction Paperback | Paperback Trade Fiction | trade-fiction-paperback | 2008-06-08 | 2019-11-03 | WEEKLY |
| Mass Market Paperback | Paperback Mass-Market Fiction | mass-market-paperback | 2008-06-08 | 2017-01-29 | WEEKLY |
| Paperback Nonfiction | Paperback Nonfiction | paperback-nonfiction | 2008-06-08 | 2019-11-03 | WEEKLY |
| E-Book Fiction | E-Book Fiction | e-book-fiction | 2011-02-13 | 2017-01-29 | WEEKLY |
| E-Book Nonfiction | E-Book Nonfiction | e-book-nonfiction | 2011-02-13 | 2017-01-29 | WEEKLY |
| Hardcover Advice | Hardcover Advice & Misc. | hardcover-advice | 2008-06-08 | 2013-04-21 | WEEKLY |
| Paperback Advice | Paperback Advice & Misc. | paperback-advice | 2008-06-08 | 2013-04-21 | WEEKLY |
| Advice How-To and Miscellaneous | Advice, How-To & Miscellaneous | advice-how-to-and-miscellaneous | 2013-04-28 | 2019-11-03 | WEEKLY |
| Hardcover Graphic Books | Hardcover Graphic Books | hardcover-graphic-books | 2009-03-15 | 2017-01-29 | WEEKLY |
| Paperback Graphic Books | Paperback Graphic Books | paperback-graphic-books | 2009-03-15 | 2017-01-29 | WEEKLY |
| Manga | Manga | manga | 2009-03-15 | 2017-01-29 | WEEKLY |
| Combined Print Fiction | Combined Hardcover & Paperback Fiction | combined-print-fiction | 2011-02-13 | 2013-05-12 | WEEKLY |
| Combined Print Nonfiction | Combined Hardcover & Paperback Nonfiction | combined-print-nonfiction | 2011-02-13 | 2013-05-12 | WEEKLY |
| Chapter Books | Children’s Chapter Books | chapter-books | 2008-06-08 | 2012-12-09 | WEEKLY |
| Childrens Middle Grade | Children’s Middle Grade | childrens-middle-grade | 2012-12-16 | 2015-08-23 | WEEKLY |
| Childrens Middle Grade E-Book | Children’s Middle Grade E-Book | childrens-middle-grade-e-book | 2015-08-30 | 2017-01-29 | WEEKLY |
| Childrens Middle Grade Hardcover | Children’s Middle Grade Hardcover | childrens-middle-grade-hardcover | 2015-08-30 | 2019-11-03 | WEEKLY |
| Childrens Middle Grade Paperback | Children’s Middle Grade Paperback | childrens-middle-grade-paperback | 2015-08-30 | 2017-01-29 | WEEKLY |
| Paperback Books | Children’s Paperback Books | paperback-books | 2008-06-08 | 2012-12-09 | WEEKLY |
| Picture Books | Children’s Picture Books | picture-books | 2008-06-08 | 2019-11-03 | WEEKLY |
| Series Books | Children’s Series | series-books | 2008-06-08 | 2019-11-03 | WEEKLY |
| Young Adult | Young Adult | young-adult | 2012-12-16 | 2015-08-23 | WEEKLY |
| Young Adult E-Book | Young Adult E-Book | young-adult-e-book | 2015-08-30 | 2017-01-29 | WEEKLY |
| Young Adult Hardcover | Young Adult Hardcover | young-adult-hardcover | 2015-08-30 | 2019-11-03 | WEEKLY |
| Young Adult Paperback | Young Adult Paperback | young-adult-paperback | 2015-08-30 | 2017-01-29 | WEEKLY |
| Animals | Animals | animals | 2014-09-07 | 2017-01-15 | MONTHLY |
| Audio Fiction | Audio Fiction | audio-fiction | 2018-03-11 | 2019-10-13 | MONTHLY |
| Audio Nonfiction | Audio Nonfiction | audio-nonfiction | 2018-03-11 | 2019-10-13 | MONTHLY |
| Business Books | Business | business-books | 2013-11-03 | 2019-10-13 | MONTHLY |
| Celebrities | Celebrities | celebrities | 2014-09-07 | 2017-01-15 | MONTHLY |
| Crime and Punishment | Crime and Punishment | crime-and-punishment | 2014-10-12 | 2017-01-15 | MONTHLY |
| Culture | Culture | culture | 2014-10-12 | 2017-01-15 | MONTHLY |
| Education | Education | education | 2014-10-12 | 2017-01-15 | MONTHLY |
| Espionage | Espionage | espionage | 2014-12-14 | 2017-01-15 | MONTHLY |
| Expeditions Disasters and Adventures | Expeditions | expeditions-disasters-and-adventures | 2014-12-14 | 2017-01-15 | MONTHLY |
| Fashion Manners and Customs | Fashion, Manners and Customs | fashion-manners-and-customs | 2014-10-12 | 2017-01-15 | MONTHLY |
| Food and Fitness | Food and Diet | food-and-fitness | 2013-09-01 | 2017-01-15 | MONTHLY |
| Games and Activities | Games and Activities | games-and-activities | 2014-10-12 | 2017-01-15 | MONTHLY |
| Graphic Books and Manga | Graphic Books and Manga | graphic-books-and-manga | 2019-10-13 | 2019-10-13 | MONTHLY |
| Hardcover Business Books | Hardcover Business Books | hardcover-business-books | 2011-07-03 | 2013-10-13 | MONTHLY |
| Health | Health | health | 2014-10-12 | 2017-01-15 | MONTHLY |
| Humor | Humor | humor | 2014-09-07 | 2017-01-15 | MONTHLY |
| Indigenous Americans | Indigenous Americans | indigenous-americans | 2014-12-14 | 2016-01-10 | MONTHLY |
| Relationships | Love and Relationships | relationships | 2014-09-07 | 2017-01-15 | MONTHLY |
| Mass Market Monthly | Mass Market | mass-market-monthly | 2019-10-13 | 2019-10-13 | MONTHLY |
| Middle Grade Paperback Monthly | Middle Grade Paperback | middle-grade-paperback-monthly | 2019-10-13 | 2019-10-13 | MONTHLY |
| Paperback Business Books | Paperback Business Books | paperback-business-books | 2011-07-03 | 2013-10-13 | MONTHLY |
| Family | Parenthood and Family | family | 2014-09-07 | 2017-01-15 | MONTHLY |
| Hardcover Political Books | Politics and American History | hardcover-political-books | 2011-07-03 | 2017-01-15 | MONTHLY |
| Race and Civil Rights | Race and Civil Rights | race-and-civil-rights | 2014-12-14 | 2017-01-15 | MONTHLY |
| Religion Spirituality and Faith | Religion, Spirituality and Faith | religion-spirituality-and-faith | 2014-09-07 | 2017-01-15 | MONTHLY |
| Science | Science | science | 2013-04-14 | 2019-09-15 | MONTHLY |
| Sports | Sports and Fitness | sports | 2014-03-02 | 2019-09-15 | MONTHLY |
| Travel | Travel | travel | 2014-09-07 | 2017-01-15 | MONTHLY |
| Young Adult Paperback Monthly | Young Adult Paperback | young-adult-paperback-monthly | 2019-10-13 | 2019-10-13 | MONTHLY |
Get the current fiction best sellers
books <- "https://api.nytimes.com/svc/books/v3/lists/current/hardcover-fiction.json"
fiction_bestsellers <- GET(paste(books, api_key, sep = ""))
fiction_bestsellers <- fromJSON(content(fiction_bestsellers, "text"))
fiction_bestsellers <- fiction_bestsellers$results
fiction_bestsellers[1:10]
## $list_name
## [1] "Hardcover Fiction"
##
## $list_name_encoded
## [1] "hardcover-fiction"
##
## $bestsellers_date
## [1] "2019-10-19"
##
## $published_date
## [1] "2019-11-03"
##
## $published_date_description
## [1] "latest"
##
## $next_published_date
## [1] ""
##
## $previous_published_date
## [1] "2019-10-27"
##
## $display_name
## [1] "Hardcover Fiction"
##
## $normal_list_ends_at
## [1] 15
##
## $updated
## [1] "WEEKLY"
fiction_books <- fiction_bestsellers$books
fiction_books %>% select(rank, rank_last_week, weeks_on_list, primary_isbn13, title, amazon_product_url )%>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover"), fixed_thead = T)
knitr::include_graphics(fiction_books$book_image)