Eventbrite OAuth2 Example

Author

David Gerard

Learning Objectives

OAuth2 Method

library(tidyverse)
library(httr2)

Based on the docs, this is the flow (your id and secret will be different):

client <- oauth_client(
  id = "7Q4MLH2PBGUJWNWLZO",
  secret = "YQW7ZQS6LX525KTISRBBAI5MVAEYLDY6IT6V3IDKLHSOP3JT5O",
  token_url = "https://www.eventbrite.com/oauth/token"
)
auth_url <- "https://www.eventbrite.com/oauth/authorize"
redirect_uri <- "http://localhost:1410/"

You can get a token this way and then reuse it:

## Get the token
token <- oauth_flow_auth_code(
  client = client,
  auth_url = auth_url,
  redirect_uri = redirect_uri
)
request("https://www.eventbriteapi.com/v3") |>
  req_url_path_append("categories") |>
  req_url_query(token = token$access_token) |>
  req_perform() ->
  rout

Or you can cache the token after one use (recommended):

request("https://www.eventbriteapi.com/v3") |>
  req_url_path_append("categories") |>
  req_oauth_auth_code(
    client = client, 
    auth_url = auth_url,
    redirect_uri = redirect_uri, 
    cache_disk = TRUE) |>
  req_perform() ->
  rout

Here is the output:

tibble(dat = resp_body_json(rout)[[3]]) |>
  unnest_wider(dat)
# A tibble: 21 × 6
   resource_uri       id    name  name_localized short_name short_name_localized
   <chr>              <chr> <chr> <chr>          <chr>      <chr>               
 1 https://www.event… 103   Music Music          Music      Music               
 2 https://www.event… 101   Busi… Business & Pr… Business   Business            
 3 https://www.event… 110   Food… Food & Drink   Food & Dr… Food & Drink        
 4 https://www.event… 113   Comm… Community & C… Community  Community           
 5 https://www.event… 105   Perf… Performing & … Arts       Arts                
 6 https://www.event… 104   Film… Film, Media &… Film & Me… Film & Media        
 7 https://www.event… 108   Spor… Sports & Fitn… Sports & … Sports & Fitness    
 8 https://www.event… 107   Heal… Health & Well… Health     Health              
 9 https://www.event… 102   Scie… Science & Tec… Science &… Science & Tech      
10 https://www.event… 109   Trav… Travel & Outd… Travel & … Travel & Outdoor    
# ℹ 11 more rows

API Key method