The New York Times web site provides a rich set of APIs, as described here. 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.
Read the data having movie reviews of Harry Potter, GOdfather and Jurassic Park from the API.
nyt_key <- "VnkQnIsatF3PkvjPsr78YUYFUtkfIvdz"
url_1 <- "https://api.nytimes.com/svc/movies/v2/reviews/search.json?query=harry%20potter&api-key="
data_1 <- fromJSON (paste0(url_1,nyt_key))
url_2 <- "https://api.nytimes.com/svc/movies/v2/reviews/search.json?query=godfather&api-key="
data_2 <- fromJSON (paste0(url_2,nyt_key))
url_3 <- "https://api.nytimes.com/svc/movies/v2/reviews/search.json?query=jurassic%20park&api-key="
data_3 <- fromJSON (paste0(url_3,nyt_key))
Load into 3 data frames
data_1 <- data.frame(data_1)
data_2 <- data.frame(data_2)
data_3 <- data.frame(data_3)
The 3 dataframes are combined into a single data frame ‘final’. The required coloumns are selected from the dataframe and the columns are renamed.
final <- dplyr::bind_rows(data_1,data_2,data_3)
final <- final %>% select(results.display_title, results.byline, results.headline, results.summary_short, results.publication_date)
names <- c('Title', 'Author', 'Headline', 'Short Summary', 'Date of Publication')
colnames(final) <- names
datatable(final)