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.

Read libraries

library(httr)
library(jsonlite)
library(tidyverse)

For this assignment, I chose the movie reviews New York Times APIs.

Construct path to get movie reviews that are critics’ picks

api_movies <- "https://api.nytimes.com/svc/movies/v2/reviews/picks.json?api-key="
api_key <- "BJty2Wsivb3jXJ8YT5cHoraopLGGTpMl"
api_path <- paste(api_movies,api_key, sep = "")

Read json data and convert it into R dataframe

api_call <- fromJSON(api_path, flatten = TRUE) %>% data.frame()

View the api data

glimpse(api_call)
## Rows: 20
## Columns: 20
## $ status                           <chr> "OK", "OK", "OK", "OK", "OK", "OK", "…
## $ copyright                        <chr> "Copyright (c) 2022 The New York Time…
## $ has_more                         <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, T…
## $ num_results                      <int> 20, 20, 20, 20, 20, 20, 20, 20, 20, 2…
## $ results.display_title            <chr> "Armageddon Time", "The Novelist's Fi…
## $ results.mpaa_rating              <chr> "R", "", "PG", "", "R", "", "PG-13", …
## $ results.critics_pick             <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
## $ results.byline                   <chr> "A.O. Scott", "Austin Considine", "Li…
## $ results.headline                 <chr> "‘Armageddon Time’ Review: Hard Lesso…
## $ results.summary_short            <chr> "New York in 1980 is the setting for …
## $ results.publication_date         <chr> "2022-10-27", "2022-10-27", "2022-10-…
## $ results.opening_date             <chr> "2022-11-04", NA, "2022-10-21", NA, "…
## $ results.date_updated             <chr> "2022-10-27 16:56:03", "2022-10-27 11…
## $ results.link.type                <chr> "article", "article", "article", "art…
## $ results.link.url                 <chr> "https://www.nytimes.com/2022/10/27/m…
## $ results.link.suggested_link_text <chr> "Read the New York Times Review of Ar…
## $ results.multimedia.type          <chr> "mediumThreeByTwo210", "mediumThreeBy…
## $ results.multimedia.src           <chr> "https://static01.nyt.com/images/2022…
## $ results.multimedia.height        <int> 140, 140, 140, 140, 140, 140, 140, 14…
## $ results.multimedia.width         <int> 210, 210, 210, 210, 210, 210, 210, 21…

Conclusion

In this assignment, I chose movie reviews New York Times API. Further, I generated the api key for the app. Finally, I read the json movie review data and converted into R dataframe.