Assignment_6

The Open Movie Database API

The Open Movie Database (OMDb) is a collection of data about movies and tv shows. It provides useful information like titles, actors, summaries, and ratings. Someone would want to use the OMDb API because it makes it very easy to gather and analyze movie and tv show data.

Load the packages

Load httr, jsonlite, and tidyverse.

library(httr)
library(jsonlite)
library(tidyverse)
── 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.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter()  masks stats::filter()
✖ purrr::flatten() masks jsonlite::flatten()
✖ dplyr::lag()     masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors

make the api key in r

go to https://www.omdbapi.com/apikey.aspx and make an account for free. After completing completing the steps they tell you, theywill email you a key. Activate the key through the email then paste it into R.

api_key <- "b2ba179c"  # Replace with your own key

Connect the endpoint

Use this as the endpoint.

endpoint <- "https://www.omdbapi.com/"

Combine the URL parts

This will make the full url.

url <- paste0(endpoint, "?", title, "&apikey=", api_key)

Make the API request

API_Request <- GET(url)

Run it in R to get the full url.

url
[1] "https://www.omdbapi.com/?s=Inception&apikey=b2ba179c"

Making it into a Dataframe

Run this code to help tidy the data.

data <- API_Request %>%
  content(as = "text", encoding = "UTF-8") %>%
  fromJSON()

make it a Dataframe

movie_df <- as.data.frame(data)

Run it to view

movie_df
                            Search.Title Search.Year Search.imdbID Search.Type
1                              Inception        2010     tt1375666       movie
2               Inception: The Cobol Job        2010     tt5295894       movie
3                   The Crack: Inception        2019     tt6793710       movie
4  Inception: Jump Right Into the Action        2010     tt5295990       movie
5               Inception: Motion Comics       2010–     tt1790736      series
6                              Inception        2014     tt7321322       movie
7                      Madness Inception        2022    tt29258696       movie
8     Inception: 4Movie Premiere Special        2010     tt1686778       movie
9                  Cyberalien: Inception        2017     tt7926130       movie
10                    WWA: The Inception        2001     tt0311992       movie
                                                                                                                        Search.Poster
1                                  https://m.media-amazon.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg
2  https://m.media-amazon.com/images/M/MV5BMjE0NGIwM2EtZjQxZi00ZTE5LWExN2MtNDBlMjY1ZmZkYjU3XkEyXkFqcGdeQXVyNjMwNzk3Mjk@._V1_SX300.jpg
3                  https://m.media-amazon.com/images/M/MV5BZTc4MDliNjAtYmU4YS00NmQzLWEwNjktYTQ2MGFjNDc5MDhlXkEyXkFqcGc@._V1_SX300.jpg
4  https://m.media-amazon.com/images/M/MV5BZGFjOTRiYjgtYjEzMS00ZjQ2LTkzY2YtOGQ0NDI2NTVjOGFmXkEyXkFqcGdeQXVyNDQ5MDYzMTk@._V1_SX300.jpg
5  https://m.media-amazon.com/images/M/MV5BNGRkYzkzZmEtY2YwYi00ZTlmLTgyMTctODE0NTNhNTVkZGIxXkEyXkFqcGdeQXVyNjE4MDMwMjk@._V1_SX300.jpg
6                  https://m.media-amazon.com/images/M/MV5BOTY3OGFlNTktYTJiZi00ZWMxLTk4MjQtNmJiODkxYThiNjg4XkEyXkFqcGc@._V1_SX300.jpg
7                                                                                                                                 N/A
8                                                                                                                                 N/A
9                                                                                                                                 N/A
10 https://m.media-amazon.com/images/M/MV5BNTEyNGJjMTMtZjZhZC00ODFkLWIyYzktN2JjMTcwMmY5MDJlXkEyXkFqcGdeQXVyNDkwMzY5NjQ@._V1_SX300.jpg
   totalResults Response
1            38     True
2            38     True
3            38     True
4            38     True
5            38     True
6            38     True
7            38     True
8            38     True
9            38     True
10           38     True