knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
R wrapper to the YouTube Analytics API.
# install.packages("remotes") remotes::install_github("JohnCoene/ytr")
ytr_oauth
- Authenticateytr_reports
- Get dataytr_parse
- Parse resultsCreate a free application in the Google Console to obtain your client and secret.
# OAuth token <- ytr_oauth("something.apps.googleusercontent.com", "xxXx0X0x0X0xXX0")
token <- readRDS("token.rds")
It's not the most approachable API, even though it consists of just one endpoint, a good place to start is the "sample requests" page.
library(ytr) # Total views and likes in the last 3 days token %>% ytr_reports() %>% ytr_parse() # Top 10 videos by subs gained in the last 7 days token %>% ytr_reports( start = Sys.Date() - 7, metrics = c("estimatedMinutesWatched","views","likes","subscribersGained"), dimensions = "video", maxResults = 10, sort = "-subscribersGained" ) %>% ytr_parse() # Filter specific videos (by ID) token %>% ytr_reports( start = Sys.Date() - 7, metrics = c("estimatedMinutesWatched","views","likes","subscribersGained"), dimensions = "video", maxResults = 10, sort = "-subscribersGained", filters = "video==x2l7KscqRro,cFhONVldyE0" ) %>% ytr_parse()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.