NYT Review API as of 2016-05-01
#required libraries
library(jsonlite)
library(knitr)
#RESULTS 0-20 AS OF 2016-05-01
NYTREVIEWS_JSON_URL1 = 'http://api.nytimes.com/svc/movies/v2/reviews/search.json?openingmurl1-date=2016-04-21;2016-05-018&api-key=YOURAPIKEYHERE'#url for api results 0-20
json_file1 <- fromJSON(NYTREVIEWS_JSON_URL1)# get json
df1 <- as.data.frame(json_file1$results) #dataframe for results
#str(df1) #view structure
#colnames(df1) #view column names
df1s<-df1[,c(1:8)] #subset needed columns
#RESULTS 21-40 AS OF 2016-05-01
NYTREVIEWS_JSON_URL2 = 'http://api.nytimes.com/svc/movies/v2/reviews/search.json?opening-date=2016-04-21;2016-05-01&api-key=YOURAPIKEYHERE&offset=20' #url for api results 20-40
json_file2 <- fromJSON(NYTREVIEWS_JSON_URL2) #get json
df2 <- as.data.frame(json_file2$results) #dataframe for results
df2s<-df2[,c(1:8)] #subset needed columns
#ALL RESULTS 0-40 COMBINED
df<- rbind(df1s,df2s) #combine all results
#knitr::kable(df, row.names =TRUE) #test
#ADD URL COLUMN TO RESULTS
url1 <- json_file1$results$link #collect links part 1
url1<-url1[,c(1:2)] #subset links
url2 <- json_file2$results$link #collect links part 2
url2<-url2[,c(1:2)] #subset links
#str(url1) #test
urls<- rbind(url1,url2) #combine all results for links
#knitr::kable(urls, row.names = TRUE) #test
combo<-cbind(df,urls) #combine reviews and links
combo<-combo[,c(1:3,7,8,10)] #subset needed columns
combo<-combo[,c(1,5,4,6,2,3)] #reorder needed columns
kable(combo, row.names = TRUE) #display with row numbers