Assignment: 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.

library(httr)
library(jsonlite)
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

#store url and api key

url<- "https://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=HuVC3AH85KUOLicBXhObdKaPA1P6jWzI"

get function to retreive data

movies <-GET(url)

#confirm the status

movies$status_code
## [1] 200

store the text format of content

text_content <- content(movies, "text")

covert to dataframe

json_content_df <- text_content %>% fromJSON() %>% as.data.frame()

display the data frame

dim(json_content_df)
## [1] 20 15
head(json_content_df)
##   status                                                           copyright
## 1     OK Copyright (c) 2022 The New York Times Company. All Rights Reserved.
## 2     OK Copyright (c) 2022 The New York Times Company. All Rights Reserved.
## 3     OK Copyright (c) 2022 The New York Times Company. All Rights Reserved.
## 4     OK Copyright (c) 2022 The New York Times Company. All Rights Reserved.
## 5     OK Copyright (c) 2022 The New York Times Company. All Rights Reserved.
## 6     OK Copyright (c) 2022 The New York Times Company. All Rights Reserved.
##   has_more num_results results.display_title results.mpaa_rating
## 1     TRUE          20              Peaceful                    
## 2     TRUE          20       Armageddon Time                   R
## 3     TRUE          20   The Novelist's Film                    
## 4     TRUE          20             Call Jane                   R
## 5     TRUE          20    Run Sweetheart Run                   R
## 6     TRUE          20        The Good Nurse                   R
##   results.critics_pick    results.byline
## 1                    0   Beatrice Loayza
## 2                    1        A.O. Scott
## 3                    1  Austin Considine
## 4                    0    Manohla Dargis
## 5                    0 Natalia Winkelman
## 6                    0     Amy Nicholson
##                                                 results.headline
## 1               ‘Peaceful’ Review: A Homage to French Filmmaking
## 2   ‘Armageddon Time’ Review: Hard Lessons About Life in America
## 3                        ‘The Novelist’s Film’ Review: Real Talk
## 4 ‘Call Jane’ Review: Abortion History That’s Being Repeated Now
## 5                    ‘Run Sweetheart Run’ Review: Escape in L.A.
## 6                          ‘The Good Nurse’ Review: Bad Medicine
##                                                                                                                                           results.summary_short
## 1            Emmanuelle Bercot’s drama about a man diagnosed with late-stage cancer plays like a eulogy for a nearly bygone era of French cinema and its stars.
## 2                                   New York in 1980 is the setting for James Gray’s brooding, bittersweet story of family conflict and interracial friendship.
## 3             In Hong Sang-soo’s latest study in small moments and chance encounters, a visit to an old friend prompts a writer in crisis to try something new.
## 4          A fictionalized drama about the Jane Collective, a clandestine group that helped women secure safe, illegal abortions before 1973, is of the moment.
## 5           Bursts of experimental style are at odds with a simplistic premise in this slasher movie that poses the tired idea that the patriarchy is a killer.
## 6 This true-crime tale, starring Eddie Redmayne and Jessica Chastain, dramatizes the story of Charles Cullen, a nurse who was discovered to be a serial killer.
##   results.publication_date results.opening_date results.date_updated
## 1               2022-10-28                 <NA>  2022-10-28 15:04:56
## 2               2022-10-27           2022-11-04  2022-10-27 16:56:03
## 3               2022-10-27                 <NA>  2022-10-27 11:05:03
## 4               2022-10-27           2022-10-28  2022-10-27 18:20:03
## 5               2022-10-27           2022-10-28  2022-10-27 16:18:03
## 6               2022-10-27           2022-10-26  2022-10-27 16:13:10
##   results.link.type
## 1           article
## 2           article
## 3           article
## 4           article
## 5           article
## 6           article
##                                                           results.link.url
## 1           https://www.nytimes.com/2022/10/28/movies/peaceful-review.html
## 2    https://www.nytimes.com/2022/10/27/movies/armageddon-time-review.html
## 3 https://www.nytimes.com/2022/10/27/movies/the-novelists-film-review.html
## 4 https://www.nytimes.com/2022/10/27/movies/call-jane-review-abortion.html
## 5 https://www.nytimes.com/2022/10/27/movies/run-sweetheart-run-review.html
## 6     https://www.nytimes.com/2022/10/27/movies/the-good-nurse-review.html
##                        results.link.suggested_link_text results.multimedia.type
## 1            Read the New York Times Review of Peaceful     mediumThreeByTwo210
## 2     Read the New York Times Review of Armageddon Time     mediumThreeByTwo210
## 3 Read the New York Times Review of The Novelist's Film     mediumThreeByTwo210
## 4           Read the New York Times Review of Call Jane     mediumThreeByTwo210
## 5  Read the New York Times Review of Run Sweetheart Run     mediumThreeByTwo210
## 6      Read the New York Times Review of The Good Nurse     mediumThreeByTwo210
##                                                                                                                            results.multimedia.src
## 1                                     https://static01.nyt.com/images/2022/10/28/arts/28peaceful-review/28peaceful-review-mediumThreeByTwo440.jpg
## 2                         https://static01.nyt.com/images/2022/10/27/multimedia/27armageddon1-1-751d/27armageddon1-1-751d-mediumThreeByTwo440.jpg
## 3                                                     https://static01.nyt.com/images/2022/10/28/arts/novelist1/novelist1-mediumThreeByTwo440.jpg
## 4 https://static01.nyt.com/images/2022/10/28/arts/27calljane-review/merlin_215188530_ebbb42de-a4da-4c36-974b-5aa8c0fc169a-mediumThreeByTwo440.jpg
## 5                                                               https://static01.nyt.com/images/2022/10/27/arts/run1/run1-mediumThreeByTwo440.jpg
## 6                                                   https://static01.nyt.com/images/2022/10/28/arts/goodnurse1/goodnurse1-mediumThreeByTwo440.jpg
##   results.multimedia.height results.multimedia.width
## 1                       140                      210
## 2                       140                      210
## 3                       140                      210
## 4                       140                      210
## 5                       140                      210
## 6                       140                      210