Step 1 : Apply for a key (Many APIs will ask for authenticators, but this restful API just asks for a user specific key inside your http request.)
Step 2 : Select from the NY times API tree, which category you would like to request information for. I chose movie reviews!
Step 3 : I use a combination of RCurl and jsonlite to retrieve and “jsonify” the object I recieve from NY times.
Step 4 : I seperate all three tables including in my object, into three different dataframes.
Bonus Step : If I were to expand on this dataframe, I would use scrapeR package to retrieve the links from the movieLinks dataframe, then use xpathSAPPLY() to retrieve genres from the review links, and add that vector to movies dataframe.
apiKey = "?api-key=5663a997971b47b1946e2c156218c2b8"
baseUrl = "https://api.nytimes.com/svc/movies/v2/reviews/search.json"
myUrl = paste(baseUrl,apiKey,sep="")
data = getURL(myUrl)
json =fromJSON(data)
# Make dataframe
movies = data.frame(json$results)
# Seperate dataframes
movieLinks = movies$link
movieMultimedia = movies$multimedia
movies$multimedia = NULL
movies$link = NULL
# Rename columns
names(movies) = c('Title','Rating','Suggested','Critic','Headline','Summary','Publication date','Release date','Updated date')
# Change binary results to plain english
movies$Suggested[movies$Suggested==1] = 'Yes'
movies$Suggested[movies$Suggested==0] = 'No'
kable(head(movies),format="markdown")
Five Came Back |
|
Yes |
BEN KENIGSBERG |
Review: ‘Five Came Back,’ and Inspired the Likes of Spielberg |
A screen adaptation of Mark Harris’s 2014 book adds visuals to the story of five Hollywood directors who served in World War II with cameras in tow. |
2017-03-30 |
2017-03-31 |
2017-03-30 21:44:03 |
The Blackcoat’s Daughter |
R |
Yes |
JEANNETTE CATSOULIS |
Review: ‘The Blackcoat’s Daughter’ Is Bewitching and Bloody |
Three narratives converge in a gorgeously filmed, deeply unsettling horror film about girls stranded at their boarding school during midterm break. |
2017-03-30 |
NA |
2017-04-02 16:44:25 |
The Death of Louis XIV |
|
Yes |
GLENN KENNY |
Review: ‘The Death of Louis XIV’ Has a Riveting Performance at Its Heart |
Albert Serra’s new film is a showcase for a beloved star of French cinema, Jean-Pierre Léaud. |
2017-03-30 |
NA |
2017-04-02 16:44:23 |
God Knows Where I Am |
|
Yes |
ANDY WEBSTER |
Review: A Descent Into Mental Illness in ‘God Knows Where I Am’ |
A documentary recalls the life of Linda Bishop, who had a psychotic disorder and fell through the cracks of New Hampshire’s medical establishment. |
2017-03-30 |
NA |
2017-04-02 16:44:22 |
Ghost in the Shell |
PG-13 |
No |
MANOHLA DARGIS |
Review: In ‘Ghost in the Shell,’ a Cyborg With Soul |
Scarlett Johansson, playing a cyborg called Major, rises above it all in the thrill-free science fiction thriller. |
2017-03-30 |
2017-03-31 |
2017-04-02 16:44:26 |
All This Panic |
|
No |
JEANNETTE CATSOULIS |
Review: ‘All This Panic,’ a Cinematic Confidant of Teenage Girls |
This limber, light-footed documentary becomes a sort of dreamy film diary for the girls it profiles. |
2017-03-30 |
2017-03-31 |
2017-04-02 16:44:25 |