Assignment – Web APIs
I chose the Moview Reviews API for the NYTimes.
library(jsonlite)
library(XML)
library(knitr)
library(httr)
library(lubridate)
library(tidyr)
#Import Json
moviesreviews <- fromJSON("https://api.nytimes.com/svc/movies/v2/reviews/search.json?api-key=9f2d716acf3141258fe2426cf7079747") %>% as.data.frame()
head(moviesreviews)
moviesreviews$results.opening_date[is.na(moviesreviews$results.opening_date)]<-""
head(moviesreviews)
## status
## 1 OK
## 2 OK
## 3 OK
## 4 OK
## 5 OK
## 6 OK
## copyright
## 1 Copyright (c) 2017 The New York Times Company. All Rights Reserved.
## 2 Copyright (c) 2017 The New York Times Company. All Rights Reserved.
## 3 Copyright (c) 2017 The New York Times Company. All Rights Reserved.
## 4 Copyright (c) 2017 The New York Times Company. All Rights Reserved.
## 5 Copyright (c) 2017 The New York Times Company. All Rights Reserved.
## 6 Copyright (c) 2017 The New York Times Company. All Rights Reserved.
## has_more num_results results.display_title results.mpaa_rating
## 1 TRUE 20 Karl Marx City
## 2 TRUE 20 Phillauri
## 3 TRUE 20 Life R
## 4 TRUE 20 I Called Him Morgan
## 5 TRUE 20 American Anarchist
## 6 TRUE 20 CHIPS R
## results.critics_pick results.byline
## 1 1 A. O. SCOTT
## 2 0 ANDY WEBSTER
## 3 0 BEN KENIGSBERG
## 4 0 A. O. SCOTT
## 5 0 BEN KENIGSBERG
## 6 0 JEANNETTE CATSOULIS
## results.headline
## 1 Review: ‘Karl Marx City’ Revisits the Everyday Terror of Dictatorship
## 2 Review: ‘Phillauri,’ an Indian Rom-Com With an Epic Sweep
## 3 Review: In ‘Life,’ Extraterrestrial Fun, Until Someone Gets Hurt
## 4 Review: ‘I Called Him Morgan,’ a Jazz Tale of Talent and Tragedy
## 5 Review: ‘American Anarchist’ Is a Frustrating Study in Denial
## 6 Review: In ‘CHIPS,’ Blown-Up Cars Overshadow Buddy Cops
## results.summary_short
## 1 In this documentary, a filmmaker returns to her hometown in the former East Germany seeking personal and political insight.
## 2 Anshai Lal’s Bollywood movie uses a friendly ghost to turn a contemporary comedy into a historical drama that includes a massacre under British rule.
## 3 This movie offers proof of life on another planet, sure, but it is also the occasion for another “Alien”-type deadly game of hide-and-seek.
## 4 The director Kasper Collin has created a suave and sensitive documentary about the life and death of the great trumpeter Lee Morgan.
## 5 A dialogue between the director and the author of “The Anarchist Cookbook” is at the heart of this documentary.
## 6 This unrepentantly lewd comedy, based on the 1977-83 television series of the same name, stars Dax Shepard, who also wrote and directed.
## results.publication_date results.opening_date results.date_updated
## 1 2017-03-28 2017-03-29 2017-03-29 16:44:25
## 2 2017-03-26 2017-03-24 2017-03-29 16:44:25
## 3 2017-03-23 2017-03-24 2017-03-29 16:44:25
## 4 2017-03-23 2017-03-24 2017-03-29 16:44:24
## 5 2017-03-23 2017-03-29 16:44:24
## 6 2017-03-23 2017-03-24 2017-03-29 16:44:23
## results.link.type
## 1 article
## 2 article
## 3 article
## 4 article
## 5 article
## 6 article
## results.link.url
## 1 http://www.nytimes.com/2017/03/28/movies/karl-marx-city-review.html
## 2 http://www.nytimes.com/2017/03/26/movies/phillauri-review.html
## 3 http://www.nytimes.com/2017/03/23/movies/life-review-jake-gyllenhaal-ryan-reynolds.html
## 4 http://www.nytimes.com/2017/03/23/movies/i-called-him-morgan-review.html
## 5 http://www.nytimes.com/2017/03/23/movies/american-anarchist-review.html
## 6 http://www.nytimes.com/2017/03/23/movies/chips-review.html
## results.link.suggested_link_text
## 1 Read the New York Times Review of Karl Marx City
## 2 Read the New York Times Review of Phillauri
## 3 Read the New York Times Review of Life
## 4 Read the New York Times Review of I Called Him Morgan
## 5 Read the New York Times Review of American Anarchist
## 6 Read the New York Times Review of CHIPS
## results.multimedia.type
## 1 mediumThreeByTwo210
## 2 mediumThreeByTwo210
## 3 mediumThreeByTwo210
## 4 mediumThreeByTwo210
## 5 mediumThreeByTwo210
## 6 mediumThreeByTwo210
## results.multimedia.src
## 1 https://static01.nyt.com/images/2017/03/29/arts/29KARLMARX/29KARLMARX-mediumThreeByTwo210.jpg
## 2 https://static01.nyt.com/images/2017/03/27/arts/27PHILLAURI/27PHILLAURI-mediumThreeByTwo210.jpg
## 3 https://static01.nyt.com/images/2017/03/24/arts/24LIFE/24LIFE-mediumThreeByTwo210.jpg
## 4 https://static01.nyt.com/images/2017/03/24/arts/24ICALLEDMORGAN/24ICALLEDMORGAN-mediumThreeByTwo210.jpg
## 5 https://static01.nyt.com/images/2017/02/01/movies/video-american-anarchist/video-american-anarchist-mediumThreeByTwo210.jpg
## 6 https://static01.nyt.com/images/2017/03/24/arts/24CHIPS/24CHIPS-mediumThreeByTwo210.jpg
## results.multimedia.width results.multimedia.height
## 1 210 140
## 2 210 140
## 3 210 140
## 4 210 140
## 5 210 140
## 6 210 140
As you can see from the head(moviesreviews) the data is stored as a frame.