HW #6- OMDB API

Author

Nick Moscovic

OMDB Explanation

The OMDB API is a web service that enables users to get information about movies. It is especially useful because it pulls ratings and movie information from three different platforms (Rotten Tomatoes, Metacritic, IMDb). Users can easily search up information on their favorite movies or their favorite actor’s filmography.

Walkthrough:

The first step is to load the necessary packages.

library(tidyverse) 
library(jsonlite)  
library(magrittr) 
library(httr)    
library(knitr)

The user then has to obtain their own API key. This can be done at the following website: https://www.omdbapi.com/apikey.aspx. After the API key is obtained, the user can build a URL with a spot to put their own API key. For this example, I am using my own API key and the movie Ghostbusters. A different user would need to put their own API key in that line.

endpoint<- "https://www.omdbapi.com/?t="
API_key<-"&apikey=4725021"
movie<- "Ghostbusters"
movie_url<- paste0(endpoint,URLencode(movie),API_key)

The next step is to create a GET function that will take the URL and transform the text into a JSON format.

Get_movie<-
  movie_url %>% 
  GET() %>% 
  content(as = "text",
          encoding = "UTF-8") %>% 
  fromJSON()

Once the data is in a JSON format, the last step is to create a data frame that will have the desired information for the movie. For this example, I want to see the title, the IMDb rating, the actors, the awards, and how much money it made at the box office.

Ghostbusters_data<- data.frame(Title = Get_movie$Title,
                       imdbRating = Get_movie$imdbRating,
                       Actors = Get_movie$Actors,
                       Awards= Get_movie$Awards,
                       Revenue = Get_movie$BoxOffice
                       )

Final Result

Ghostbusters_data %>% 
  select(Title, imdbRating, Actors, Awards, Revenue)
         Title imdbRating                                     Actors
1 Ghostbusters        7.8 Bill Murray, Dan Aykroyd, Sigourney Weaver
                                                Awards      Revenue
1 Nominated for 2 Oscars. 9 wins & 9 nominations total $243,640,120

This data is now organized into one clean table that makes sense and is easy to read. These results are easily reproducible with just a few minor changes. The only changes that would need to be made is to the API_key line and the movie line in the second code chunk. By changing those, a user can find data on any movie.