library(tidyverse)
library(jsonlite)
library(magrittr)
library(httr)
library(jsonlite)Assignment 6 API’s
API Introduction
The API that I have chose today is the omdb API. The main use of this API is to gather information about movies, series and episodes. This includes summaries, the year, and IMDB id.
Obtaining the API key
In order to properly use this API and its functions, you first must obtain an API key. In order to do this, one must go to the webpage: http://www.omdbapi.com and click on the API key tab at the top of the page. From this API page, you must fill out your information to get a personalized API key to use the API.
Example API model
First Install the packages below to be able to execute the model:
Here is an example of how to run the API with a model I’ve created:
api_key <- "[API_key]"
title <- "The Avengers"
encoded_title <- URLencode(title)
omdb_url <- paste0("http://www.omdbapi.com/?apikey=", api_key,
"&t=", encoded_title,
"&type=movie",
"&y=2012",
"&plot=full")
print(omdb_url)[1] "http://www.omdbapi.com/?apikey=[API_key]&t=The%20Avengers&type=movie&y=2012&plot=full"
response <- GET(omdb_url)
content_text <- content(response, as = "text", encoding = "UTF-8")
json_data <- fromJSON(content_text)
omdb_df <- as.data.frame(json_data)
print(omdb_df) Response Error
1 False Invalid API key!
Based off the example model I’ve created, we are printing the results from imdb from a a movie we have selected. Any movie title can be plugged in to the title value as well as the other values to find the imdb information for any movie on the platform.