Assignment 6: Learning a New API

Author

Jim Scola

Why Use OMBD?

OMDB is essentially an API for IMDB, and can thus be used to search for movies, shows, and episodes within its database and their accompanying information. This could be useful to someone who is looking for movies based on certain criteria, especially its title, as that or its IMDB ID is a required field in the API call. OMDB can be used to compare data across movies, shows, or episodes, such as ratings from different sources such as Rotten Tomatoes or Metacritic for each movie in a series.

Setup for OMDB

Before you can make an API call from OMDB, you will need an API key from them. The process is simple, you would go to their website at https://www.omdbapi.com/ and then head to the API key tab. From there, you would fill out your first and last name, email address, and the purpose for using the API. It will then send you an email with the API key, which should be included in all calls you make on OMDB.

Next, you will need some packages to get to the final API call. The packages needed are listed below with the

library(tidyverse) # For a variety of Tidyverse functions
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(jsonlite)  # For taking JSON data and making it into data frames

Attaching package: 'jsonlite'

The following object is masked from 'package:purrr':

    flatten
library(magrittr)  # For extracting items from list objects using piping grammar

Attaching package: 'magrittr'

The following object is masked from 'package:purrr':

    set_names

The following object is masked from 'package:tidyr':

    extract
library(httr)      # For HTTP interactions

API Call Demonstration

From there, you would create multiple objects with the endpoint and the individual parameters you require. The OMDB database has two ways in which you call data . The call they name By ID or Title, you must use either i= or t= as a parameter, as you are either searching a specific IMDB ID or title as the name implies. This method searches for a single specific movie, series, or episode, but provides greater information such as actors, producers, writers, ratings, and genre(s), among many other more descriptive data about the media. Alternatively, you can use the call named By Search, which requires you use a s= parameter. This method searches for multiple movies, series, or episodes that meet its criteria. However, its information is relatively sparse, showing its title, the year it came out, a link to its poster, its IMDB ID, and what kind of video media it is. As such, it would likely be best to use them in tandem, with the By Search function providing the IMDB IDs for a function to compile all of the By ID or Title results for each instance.

NOTE: Spaces are able to be included. For example, the search I used was “star_wars”.

read.csv("C:/Users/Jim Scola/OneDrive - Xavier University/Documents/OMDB Title API Data.csv")
                               Title Year Rated    Released Runtime
1 Star Wars: Episode IV - A New Hope 1977    PG 25 May 1977 121 min
2 Star Wars: Episode IV - A New Hope 1977    PG 25 May 1977 121 min
3 Star Wars: Episode IV - A New Hope 1977    PG 25 May 1977 121 min
                       Genre     Director       Writer
1 Action, Adventure, Fantasy George Lucas George Lucas
2 Action, Adventure, Fantasy George Lucas George Lucas
3 Action, Adventure, Fantasy George Lucas George Lucas
                                     Actors
1 Mark Hamill, Harrison Ford, Carrie Fisher
2 Mark Hamill, Harrison Ford, Carrie Fisher
3 Mark Hamill, Harrison Ford, Carrie Fisher
                                                                                                                                                                                                                                                                                                                                                                                              Plot
1 The Imperial Forces, under orders from cruel Darth Vader, hold Princess Leia hostage in their efforts to quell the rebellion against the Galactic Empire. Luke Skywalker and Han Solo, captain of the Millennium Falcon, work together with the companionable droid duo R2-D2 and C-3PO to rescue the beautiful princess, help the Rebel Alliance and restore freedom and justice to the Galaxy.
2 The Imperial Forces, under orders from cruel Darth Vader, hold Princess Leia hostage in their efforts to quell the rebellion against the Galactic Empire. Luke Skywalker and Han Solo, captain of the Millennium Falcon, work together with the companionable droid duo R2-D2 and C-3PO to rescue the beautiful princess, help the Rebel Alliance and restore freedom and justice to the Galaxy.
3 The Imperial Forces, under orders from cruel Darth Vader, hold Princess Leia hostage in their efforts to quell the rebellion against the Galactic Empire. Luke Skywalker and Han Solo, captain of the Millennium Falcon, work together with the companionable droid duo R2-D2 and C-3PO to rescue the beautiful princess, help the Rebel Alliance and restore freedom and justice to the Galaxy.
  Language       Country                                       Awards
1  English United States Won 6 Oscars. 69 wins & 30 nominations total
2  English United States Won 6 Oscars. 69 wins & 30 nominations total
3  English United States Won 6 Oscars. 69 wins & 30 nominations total
                                                                                                              Poster
1 https://m.media-amazon.com/images/M/MV5BOGUwMDk0Y2MtNjBlNi00NmRiLTk2MWYtMGMyMDlhYmI4ZDBjXkEyXkFqcGc@._V1_SX300.jpg
2 https://m.media-amazon.com/images/M/MV5BOGUwMDk0Y2MtNjBlNi00NmRiLTk2MWYtMGMyMDlhYmI4ZDBjXkEyXkFqcGc@._V1_SX300.jpg
3 https://m.media-amazon.com/images/M/MV5BOGUwMDk0Y2MtNjBlNi00NmRiLTk2MWYtMGMyMDlhYmI4ZDBjXkEyXkFqcGc@._V1_SX300.jpg
           Ratings.Source Ratings.Value Metascore imdbRating imdbVotes
1 Internet Movie Database        8.6/10        90        8.6 1,498,082
2         Rotten Tomatoes           93%        90        8.6 1,498,082
3              Metacritic        90/100        90        8.6 1,498,082
     imdbID  Type DVD    BoxOffice Production Website Response
1 tt0076759 movie N/A $460,998,507        N/A     N/A     True
2 tt0076759 movie N/A $460,998,507        N/A     N/A     True
3 tt0076759 movie N/A $460,998,507        N/A     N/A     True

An example of a By ID or Title API Call

read.csv("C:/Users/Jim Scola/OneDrive - Xavier University/Documents/OMDB API Data.csv")
                                     Search.Title Search.Year Search.imdbID
1              Star Wars: Episode IV - A New Hope        1977     tt0076759
2  Star Wars: Episode V - The Empire Strikes Back        1980     tt0080684
3      Star Wars: Episode VI - Return of the Jedi        1983     tt0086190
4      Star Wars: Episode VII - The Force Awakens        2015     tt2488496
5       Star Wars: Episode I - The Phantom Menace        1999     tt0120915
6    Star Wars: Episode III - Revenge of the Sith        2005     tt0121766
7    Star Wars: Episode II - Attack of the Clones        2002     tt0121765
8                    Rogue One: A Star Wars Story        2016     tt3748528
9         Star Wars: Episode VIII - The Last Jedi        2017     tt2527336
10  Star Wars: Episode IX - The Rise of Skywalker        2019     tt2527338
   Search.Type
1        movie
2        movie
3        movie
4        movie
5        movie
6        movie
7        movie
8        movie
9        movie
10       movie
                                                                                                        Search.Poster
1  https://m.media-amazon.com/images/M/MV5BOGUwMDk0Y2MtNjBlNi00NmRiLTk2MWYtMGMyMDlhYmI4ZDBjXkEyXkFqcGc@._V1_SX300.jpg
2  https://m.media-amazon.com/images/M/MV5BMTkxNGFlNDktZmJkNC00MDdhLTg0MTEtZjZiYWI3MGE5NWIwXkEyXkFqcGc@._V1_SX300.jpg
3  https://m.media-amazon.com/images/M/MV5BNWEwOTI0MmUtMGNmNy00ODViLTlkZDQtZTg1YmQ3MDgyNTUzXkEyXkFqcGc@._V1_SX300.jpg
4                  https://m.media-amazon.com/images/M/MV5BOTAzODEzNDAzMl5BMl5BanBnXkFtZTgwMDU1MTgzNzE@._V1_SX300.jpg
5  https://m.media-amazon.com/images/M/MV5BODVhNGIxOGItYWNlMi00YTA0LWI3NTctZmQxZGUwZDEyZWI4XkEyXkFqcGc@._V1_SX300.jpg
6                  https://m.media-amazon.com/images/M/MV5BNTc4MTc3NTQ5OF5BMl5BanBnXkFtZTcwOTg0NjI4NA@@._V1_SX300.jpg
7  https://m.media-amazon.com/images/M/MV5BNTgxMjY2YzUtZmVmNC00YjAwLWJlODMtNDBhNzllNzIzMjgxXkEyXkFqcGc@._V1_SX300.jpg
8                  https://m.media-amazon.com/images/M/MV5BMjEwMzMxODIzOV5BMl5BanBnXkFtZTgwNzg3OTAzMDI@._V1_SX300.jpg
9                  https://m.media-amazon.com/images/M/MV5BMjQ1MzcxNjg4N15BMl5BanBnXkFtZTgwNzgwMjY4MzI@._V1_SX300.jpg
10 https://m.media-amazon.com/images/M/MV5BODg5ZTNmMTUtYThlNy00NjljLWE0MGUtYmQ1NDg4NWU5MjQ1XkEyXkFqcGc@._V1_SX300.jpg
   totalResults Response
1           911     True
2           911     True
3           911     True
4           911     True
5           911     True
6           911     True
7           911     True
8           911     True
9           911     True
10          911     True

An example of a By Search API Call.