For this assignment I will be creating R code that imports movie reviews for all movies that are “Critict Picks”
library(jsonlite)
library(DT)
library(httr)
library(knitr)
# Setting up the api key and url based
apikey="VSXAPEmWO3rhAPFgDhmcY5znHGTP4Q4W"
url <- paste0("https://api.nytimes.com/svc/movies/v2/reviews/picks.json?api-key=",apikey)
# Connect to the api and use the status code for the response message. We expect a status code of 200 which would indicate the Api carried out instructions successfully
# More about status codes call be found at https://restfulapi.net/http-status-codes/
c_picks <-GET(url)
c_picks$status_code
## [1] 200
#Convert JSON object to R object ( flatten=True automatically flattens nested data frames into a single non-nested data frame)
critic_picks <- fromJSON(url, flatten = TRUE)
# The current object has mutliple elements of which $results is the data frame. As such, creating a dataframe with this element
critic_picksdf <- critic_picks$results
#Display the dataframe as a datatable
DT::datatable(critic_picksdf)
#Display a table that lists out the movie title, critic name and movie summary to make the data easier to consume
DT::datatable(critic_picksdf[c(1,4,6)])