Movie Database API

Introduction

In this assingnment, we are going to use an API on a Movie Database website that allows you to search for movies or TV series. This API allows you to search for a specific movie or TV show.

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.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(httr)
library(jsonlite)

Attaching package: 'jsonlite'

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

    flatten
library(dplyr)

Getting the API URL

To get the API to work, you are going to need the base URL that allows you to access the website.

movie_URL<-"http://www.omdbapi.com/?"

To find a movie or TV show that you specifically want, there is different search criteria that you can use to find your movie or TV show of choice.

title<-"s=Happy+Gilmore"

I chose to do the movie Happy Gilmore and the s is your specific search for a movie or TV show.

Getting your API

You have to get a specific API so that the website knows who is accessing this information and trying to webscrape their website.

api_key<-"&apikey=83544aa4"

Putting Everything Together

movie_API<-paste(movie_URL,title,api_key, sep = "")

Running this code chunk allows you to put together a full URL that will take you to the movie or TV show that you chose.

URL to Data Conversion

This R code is making it turn from a JSON format into a data format.

movie_API_Response<-
  movie_API %>% 
  GET()
movie_data <- 
  movie_API_Response %>% 
  content(as = "text",
          encoding = "UTF-8") %>% 
  fromJSON()
movie_df<-as.data.frame(movie_data)

This makes the data from JSON into a data frame is R allowing you to interact with it in R.

Final Data from API

view(movie_df)

Running this code will allow you to view all of the information from the movie or TV show that you chose.