Yelp Explanation and API Uses

Yelp is a platform for business reviews and recommendations. It provides a informative dataset that’s accessible to the public via an API. There are various ways to utilize the Yelp API,including the following:

Businesses can track and analyze customer reviews to improve their services.

Developers can create location-based applications to find restaurants, bars, and other businesses.

Can explore Yelp data to extract insights like pricing about local businesses.

API Set-up Yelp Fusion:

  1. Sign up or log in to your Yelp account on the Yelp Developers website: Yelp Developers.

  2. Create a new Yelp App by clicking on “Create App” in your developer dashboard.

  3. Fill in the necessary details, including the App Name and a description.

After creating the app, you’ll be provided with an API Key.

To use the Yelp Fusion API in R, you need to install a few packages and set up your API key.

Load required packages

library(httr)  
library(jsonlite)

Set your Yelp API key

Sys.setenv(YELP_API_KEY = 'YOUR_YELP_API_KEY')

Define the API endpoint

base_url <- "https://api.yelp.com/v3"

Function to make Yelp API requests (from Yelp Developer site)

yelp_api_request <- function(endpoint, params = list(), method = "GET") {
  url <- modify_url(base_url, path = endpoint)
  headers <- add_headers(Authorization = paste("Bearer", api_key))
  response <- httr::GET(url, query = params, headers = headers)
  stop_for_status(response)
  content(response, "parsed")
}

Example usage

Restaurants in New York

search_results <- yelp_api_request("businesses/search", params = list(term = "restaurant", location = "New York"))

Demonstration Business Endpoint - Example

The yelpr package provides an easier way to perform functions. For example, we can use business_search() to search for businesses based on specific criteria. In the following example, we will retrieve the first 5 Chinese restaurants in New York:

Load the yelpr package

library(yelpr)

Assign your Yelp Fusion API key

api_key <- readLines("yelp_app_key.txt")

Search for Chinese restaurants in New York

business_ny <- business_search(api_key = api_key,
                              location = 'New York',
                              term = "chinese",
                              limit = 5)

Extract and display business details

cat("Chinese Restaurants in New York:\n")
for (business in business_ny$businesses) {
  cat(paste(business$name, " - ", business$location$address1, "\n"))
}

The business_search() function returns a list of businesses, and you can extract details like name, address, rating, and other yelp data.

Events Endpoint - Example

The yelpr package also provides functions for event-related operations. For example, you can use event_search_featured() to get details of a featured event in a given location using longitude and latitude: