The assignment this week is to choose an API from the NY Times and construct an interface in R to read in the JSON data and transform it into a R DataFrame.
The first step was to get an API key from the NYT.
Once we had the key, the first API I used was search to find stories on the election. The process is to pull the data from the NY Times website using JSON. I then transformed it into a dataframe.
search <- fromJSON("http://api.nytimes.com/svc/search/v2/articlesearch.json?q=election&api-key=mcDcpEet9wVzcc6ys9vFZjRUJtOmN7yv", flatten = TRUE) %>%
data.frame()
head(search)
The next API was to look at the top US stories in the NY Times.
top_stories <- fromJSON("https://api.nytimes.com/svc/topstories/v2/us.json?api-key=Scz8UJ7pKtRfGDpP7Gvg27VMmCC74GlA", flatten = TRUE) %>%
data.frame()
head(top_stories)
Next I wanted to look at the most popular viewed stories in the NY Times.
most_popular_viewed <- fromJSON("https://api.nytimes.com/svc/mostpopular/v2/viewed/1.json?api-key=GS27ZQEtwATVBQ7UlLrzlpoMoGonFGR0", flatten = TRUE) %>%
data.frame()
head(most_popular_viewed)
Finally I wanted to see the most popular emailed stores in the NY Times.
most_popular_emailed <- fromJSON("https://api.nytimes.com/svc/mostpopular/v2/emailed/7.json?api-key=GS27ZQEtwATVBQ7UlLrzlpoMoGonFGR0", flatten = TRUE) %>%
data.frame()
head(most_popular_emailed)
This project was a new way to look at all the news that’s fit to print in R.