#API key: bdcd68cc34854010b1172447ab8d2587Variables were ‘critics-pick=Y’ and ‘order=by-date’
#key was added at the end of the URL
url <- "http://api.nytimes.com/svc/movies/v2/reviews/search.json?critics-pick=Y?order=by-date&api-key=bdcd68cc34854010b1172447ab8d2587"
#Send the HTML query with the GET() function
#If status_code is 200 it worked.
movie_reviews <- GET(url)
movie_reviews$status_code## [1] 200
mr_content <- content(movie_reviews, as = "parsed")
mr_content$results[[1]]$headline## [1] "Review: A <U+0091>Joan Didion<U+0092> Portrait, From an Intimate Source"
mr_content$results[[1]]$summary_short## [1] "This documentary is directed by Griffin Dunne, Ms. Didion<U+0092>s nephew, a relationship that limits the movie in certain ways, but opens it up in others."
mr_json <- toJSON(mr_content)mr_json <- fromJSON(mr_json)
mr_data_frame <- mr_json$resultscolnames(mr_data_frame)## [1] "display_title" "mpaa_rating" "critics_pick"
## [4] "byline" "headline" "summary_short"
## [7] "publication_date" "opening_date" "date_updated"
## [10] "link" "multimedia"
The ‘link’ column is a data.frame of other columns. I only want the URL. Narrow down the column names.
mr_data_frame$link <- mr_data_frame$link$url
mr_data_frame <- mr_data_frame %>%
select(display_title, mpaa_rating, critics_pick, byline, summary_short, opening_date, link)mr_data_frame[1,]## display_title mpaa_rating critics_pick
## 1 Joan Didion: The Center Will Not Hold 1
## byline
## 1 GLENN KENNY
## summary_short
## 1 This documentary is directed by Griffin Dunne, Ms. Didion<U+0092>s nephew, a relationship that limits the movie in certain ways, but opens it up in others.
## opening_date
## 1 2017-10-27
## link
## 1 http://www.nytimes.com/2017/10/24/movies/joan-didion-the-center-will-not-hold-review-griffin-dunne.html