library(tidyverse)
library(httr2)
Eventbrite OAuth2 Example
Learning Objectives
- Another example of using OAuth2 for authorization.
- EventBrite API: https://www.eventbrite.com/platform/api/#/introduction/about-our-api
- Intro to API’s: https://www.eventbrite.com/platform/docs/introduction
- Intro to Authorization: https://www.eventbrite.com/platform/docs/authentication
- https://httr2.r-lib.org/articles/oauth.html
OAuth2 Method
- For authenticating other users, you use OAuth2.
- The base URL is: https://www.eventbriteapi.com/v3
- Go to https://www.eventbrite.com/platform/ and click “Get a Free API Key”
- Go to https://www.eventbrite.com/account-settings/apps and get information on the Client Secret, and Private and Public Tokens.
- You need to tell EventBrite the redirect uri. Go to https://www.eventbrite.com/account-settings/apps, click on “API key details” and tell it the OAuth Redirect URI is http://localhost:1410/
- The docs say the API key is the client ID. The client secret is listed explicitly.
- The docs say the token URL is: https://www.eventbrite.com/oauth/token
- They say the authorization URL is: https://www.eventbrite.com/oauth/authorize
Based on the docs, this is the flow (your id and secret will be different):
<- oauth_client(
client id = "7Q4MLH2PBGUJWNWLZO",
secret = "YQW7ZQS6LX525KTISRBBAI5MVAEYLDY6IT6V3IDKLHSOP3JT5O",
token_url = "https://www.eventbrite.com/oauth/token"
)<- "https://www.eventbrite.com/oauth/authorize"
auth_url <- "http://localhost:1410/" redirect_uri
You can get a token this way and then reuse it:
## Get the token
<- oauth_flow_auth_code(
token 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
- The documents indicate that you can use an API key for private use. But I haven’t tried it.
- Go to https://www.eventbrite.com/platform/ and click “Get a Free API Key”
- The base URL is: https://www.eventbriteapi.com/v3/users/me/
- You use the query:
?token=<api_key>