Assignment 9

The New York Times web site provides a rich set of API’s, as described here: https://developer.nytimes.com/get-started You’ll need to start by signing up for an API key. Your task is to choose one of the New York Times API’s, construct an interface in R to read in the JSON data, and transform it to an R data frame.

Required Libraries

## Warning: package 'formattable' was built under R version 4.0.3

Registering for an API Key.

To request for NY Times API key, register at https://developer.nytimes.com/accounts/create.

The information about creating query and url to be used can be found here - https://developer.nytimes.com/get-started.

Web API and URL

Reading in Movie Reviews API.

#url <- GET("https://api.nytimes.com/svc/books/v3/reviews/search.json", query = list(api_key = "a0c00KjHQBFiZLcAyluklWpZDYEGK6Iy"))
#url

#APIMovie <- fromJSON("https://api.nytimes.com/svc/books/v3/reviews/search.json?api_key=xvr0sP3mu5L2qin3iAW5XFs2DK0GoHju") 
#APIMovie_table <- as.data.frame(APIMovie)
#APIMovie_table

Reading the Jason Data In R and Converting it into a Data Frame.

#url <- GET("https://api.nytimes.com/svc/books/v3/articlesearch.json", #query = list(api_key = "th5YLQ89CwVhsDPnFgxGsuFIsQmBI2d5"))
#url

#APIArticle <- fromJSON("https://api.nytimes.com/svc/books/v3/articlesearch.json?api_key=a0c00KjHQBFiZLcAyluklWpZDYEGK6Iy") 
#APIArticle_table <- as.data.frame(APIArticle)
#APIArticle_table

Reading in Top Stories API

#url <- GET("https://api.nytimes.com/svc/books/v3/home.json", query = list(api_key = "xvr0sP3mu5L2qin3iAW5XFs2DK0GoHju"))
#url

#APITopStories <- fromJSON("https://api.nytimes.com/svc/books/v3/home.json?api_key=e199c1de-1439-4a84-a18d-bed2bc87af31") 
#APITopStories_table <- as.data.frame(APITopStories)
#APITopStories_table
#as.datatable(formattable(df))

Conclusion

Eventfully, we were able to obtain some updated information on movies from the New York Times web site. According to the web site we can update our search or query up to ten times per minute or 4000 times a day, which pretty much allows us to stay current.