Assignment - Web APIs

The New York Times web site provides a rich set of APIs, as described here: http://developer.nytimes.com/docs 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 to an R dataframe.

Here, we are inputing the jsonlite and the getting the data from the nytimes api which shows the reviews about the movies.

And I used the fromJSON to read the content and convert it to R.

library(jsonlite)
## Warning: package 'jsonlite' was built under R version 3.5.1
url <- "http://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=dfe0a6838e22420b93e28bafdb1acff3"
json_data <- fromJSON(url)
str(json_data)
## List of 5
##  $ status     : chr "OK"
##  $ copyright  : chr "Copyright (c) 2018 The New York Times Company. All Rights Reserved."
##  $ has_more   : logi TRUE
##  $ num_results: int 20
##  $ results    :'data.frame': 20 obs. of  11 variables:
##   ..$ display_title   : chr [1:20] "Burning" "A Bread Factory, Part One" "A Bread Factory, Part Two" "Monrovia, Indiana" ...
##   ..$ mpaa_rating     : chr [1:20] "Not Rated" "" "" "" ...
##   ..$ critics_pick    : int [1:20] 1 1 1 1 1 1 1 1 0 0 ...
##   ..$ byline          : chr [1:20] "MANOHLA DARGIS" "BILGE EBIRI" "BILGE EBIRI" "A.O. SCOTT" ...
##   ..$ headline        : chr [1:20] "Review: In ‘Burning,’ Love Ignites a Divided World" "Review: In ‘A Bread Factory,’ Local Artists Face Off Against the World" "Review: In ‘A Bread Factory,’ Local Artists Face Off Against the World" "Review: ‘Monrovia, Indiana’ Is a Sharp, Lyrical Look at Small-Town America" ...
##   ..$ summary_short   : chr [1:20] "The great South Korean director Lee Chang-dong’s latest involves three characters subsumed by desire and rage." "An ambitious, sprawling film about the efforts of a community arts center to survive, “A Bread Factory” is a ma"| __truncated__ "An ambitious, sprawling film about the efforts of a community arts center to survive, “A Bread Factory” is a ma"| __truncated__ "Frederick Wiseman’s visit to Trump country finds that there is more to life than politics, and more to democrac"| __truncated__ ...
##   ..$ publication_date: chr [1:20] "2018-10-25" "2018-10-25" "2018-10-25" "2018-10-25" ...
##   ..$ opening_date    : chr [1:20] "2018-11-09" "2018-10-26" "2018-10-26" "2018-10-26" ...
##   ..$ date_updated    : chr [1:20] "2018-10-28 16:44:26" "2018-10-28 16:44:25" "2018-10-28 16:44:25" "2018-10-25 14:32:03" ...
##   ..$ link            :'data.frame': 20 obs. of  3 variables:
##   .. ..$ type               : chr [1:20] "article" "article" "article" "article" ...
##   .. ..$ url                : chr [1:20] "http://www.nytimes.com/2018/10/25/movies/burning-review.html" "http://www.nytimes.com/2018/10/25/movies/a-bread-factory-review.html" "http://www.nytimes.com/2018/10/25/movies/a-bread-factory-review.html" "http://www.nytimes.com/2018/10/25/movies/monrovia-indiana-review-documentary.html" ...
##   .. ..$ suggested_link_text: chr [1:20] "Read the New York Times Review of Burning" "Read the New York Times Review of A Bread Factory, Part One" "Read the New York Times Review of A Bread Factory, Part Two" "Read the New York Times Review of Monrovia, Indiana" ...
##   ..$ multimedia      :'data.frame': 20 obs. of  4 variables:
##   .. ..$ type  : chr [1:20] "mediumThreeByTwo210" "mediumThreeByTwo210" "mediumThreeByTwo210" "mediumThreeByTwo210" ...
##   .. ..$ src   : chr [1:20] "https://static01.nyt.com/images/2018/10/26/arts/26burning-top/26burning-top-mediumThreeByTwo210-v3.jpg" "https://static01.nyt.com/images/2018/10/26/arts/26bread2/26bread2-mediumThreeByTwo210-v2.jpg" "https://static01.nyt.com/images/2018/10/26/arts/26bread2/26bread2-mediumThreeByTwo210-v2.jpg" "https://static01.nyt.com/images/2018/10/26/arts/26monrovia1/26monrovia1-mediumThreeByTwo210-v3.jpg" ...
##   .. ..$ width : int [1:20] 210 210 210 210 210 210 210 210 210 210 ...
##   .. ..$ height: int [1:20] 140 140 140 140 140 140 140 140 140 140 ...

Now, we are displaying the list of the movies that are reviewed. And from that we are checking what kind of information we can get from the list.

raw_data <- json_data$results
colnames(raw_data)
##  [1] "display_title"    "mpaa_rating"      "critics_pick"    
##  [4] "byline"           "headline"         "summary_short"   
##  [7] "publication_date" "opening_date"     "date_updated"    
## [10] "link"             "multimedia"
raw_data$display_title
##  [1] "Burning"                               
##  [2] "A Bread Factory, Part One"             
##  [3] "A Bread Factory, Part Two"             
##  [4] "Monrovia, Indiana"                     
##  [5] "Border"                                
##  [6] "Shirkers"                              
##  [7] "Vaya"                                  
##  [8] "1985"                                  
##  [9] "The Dark"                              
## [10] "Viper Club"                            
## [11] "Trust Machine: The Story of Blockchain"
## [12] "Don't Go"                              
## [13] "Hunter Killer"                         
## [14] "London Fields"                         
## [15] "Foreign Land"                          
## [16] "Johnny English Strikes Again"          
## [17] "Suspiria"                              
## [18] "Life & Nothing More"                   
## [19] "Wildlife"                              
## [20] "Nigerian Prince"

Now, we have choose a movie hunter killer to see different attributes about the movie.

url <- "http://api.nytimes.com/svc/movies/v2/reviews/hunter-killer.json?api-key=dfe0a6838e22420b93e28bafdb1acff3"
json_data <- fromJSON(url)
raw_data <- json_data$results
colnames(raw_data)
##  [1] "display_title"    "mpaa_rating"      "critics_pick"    
##  [4] "byline"           "headline"         "summary_short"   
##  [7] "publication_date" "opening_date"     "date_updated"    
## [10] "link"             "multimedia"

Here, we have listed the movies that are reviewed and presented the reviews for the particular movie.

library(dplyr)
## Warning: package 'dplyr' was built under R version 3.5.1
## 
## 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
movies <- raw_data %>% select(display_title, headline)
movies
##                             display_title
## 1                                 Burning
## 2               A Bread Factory, Part One
## 3               A Bread Factory, Part Two
## 4                       Monrovia, Indiana
## 5                                  Border
## 6                                Shirkers
## 7                                    Vaya
## 8                                    1985
## 9                                The Dark
## 10                             Viper Club
## 11 Trust Machine: The Story of Blockchain
## 12                               Don't Go
## 13                          Hunter Killer
## 14                          London Fields
## 15                           Foreign Land
## 16           Johnny English Strikes Again
## 17                               Suspiria
## 18                    Life & Nothing More
## 19                               Wildlife
## 20                        Nigerian Prince
##                                                                      headline
## 1                          Review: In ‘Burning,’ Love Ignites a Divided World
## 2      Review: In ‘A Bread Factory,’ Local Artists Face Off Against the World
## 3      Review: In ‘A Bread Factory,’ Local Artists Face Off Against the World
## 4  Review: ‘Monrovia, Indiana’ Is a Sharp, Lyrical Look at Small-Town America
## 5                 Review: Sniffing Out Guilt in a Strangely Engaging ‘Border’
## 6                     Review: In ‘Shirkers,’ Stolen Footage and Dashed Dreams
## 7              Review: In ‘Vaya,’ Three Travelers Find Danger in Johannesburg
## 8               Review: In ‘1985,’ a Young Man Hides a Plague From His Family
## 9              Review: In ‘The Dark,’ a Traumatized Teenager Becomes a Zombie
## 10         Review: ‘Viper Club’ Looks Behind the Scenes of a Press Kidnapping
## 11           Review: In Boosting Blockchain, ‘Trust Machine’ Chains Itself In
## 12                 Review: In ‘Don’t Go,’ Will a Dad’s Dreams Change Reality?
## 13                 Review: ‘Hunter Killer’ Explores the Depths of Geopolitics
## 14             Review: In ‘London Fields,’ Sex, Apocalypse and Writer’s Block
## 15  Review: ‘Foreign Land’ Sees a Better Past Than Future for the Middle East
## 16           Review: Rowan Atkinson Returns in ‘Johnny English Strikes Again’
## 17                  Review: ‘Suspiria’ Is a Gaudy Freakout of Female Violence
## 18                Review: ‘Life and Nothing More’ Places Family in the Center
## 19                                Review: In ‘Wildlife,’ Passions Run Rampant
## 20                Review: Bright Young Men Stoop to Scam in ‘Nigerian Prince’