knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
The goal of ryelp is to ... MAYBE CALL YELP FUSION API V3 ONE DAY? In the meantime, check out the brute force example below. This repo created just to get a STAT 545 student unstuck and then I got intrigued.
You can install ryelp from github with:
# install.packages("devtools")
devtools::install_github("jennybc/ryelp")
This is a basic example which shows you how to solve a common problem:
## basic example code
Example of working with Yelp Fusion API from first principles (vs really exploiting httr).
library(httr)
library(purrr)
res <- POST("https://api.yelp.com/oauth2/token",
body = list(grant_type = "client_credentials",
client_id = Sys.getenv("YELP_ID"),
client_secret = Sys.getenv("YELP_SECRET")))
token <- content(res)$access_token
yelp <- "https://api.yelp.com"
term <- "coffee"
location <- "Vancouver, BC"
limit <- 3
(url <-
modify_url(yelp, path = c("v3", "businesses", "search"),
query = list(term = term, location = location, limit = limit)))
res <- GET(url, add_headers('Authorization' = paste("bearer", token)))
http_status(res)
ct <- content(res)
ct$businesses %>%
map_df(`[`, c("name", "phone"))
See httr.R.