--- title: "Using tubern" author: "Gaurav Sood" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Using tuber} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ## tubern: Access YouTube Analytics API via R ### Install, Load the package To install the latest version from CRAN: ```{r, eval=FALSE, install} install.packages("tubern") ``` The latest development version of the package will always be on GitHub. Instructions for installing the package from Github are provided below. ```{r, eval=FALSE, install_g} # install.packages('devtools') devtools::install_github("soodoku/tubern", build_vignettes = TRUE) ``` Next, load the package: ```{r, eval=FALSE, loadlib} library(tubern) ``` ### Using the package To get going, get the application id and password from Google Developer Console (see [https://developers.google.com/youtube/reporting/](https://developers.google.com/youtube/reporting/)). Enable YouTube APIs. Then set the application id and password via the `yt_oauth` function. For more information about YouTube OAuth, see [YouTube OAuth Guide](https://developers.google.com/youtube/v3/guides/authentication). ```{r, eval=FALSE, auth} yt_oauth("998136489867-5t3tq1g7hbovoj46dreqd6k5kd35ctjn.apps.googleusercontent.com", "MbOSt6cQhhFkwETXKur-L9rN") ``` ```{r, eval=FALSE, prints} ## Waiting for authentication in browser... ## Press Esc/Ctrl + C to abort ## Authentication complete. ``` #### Get Statistics of a Video ```{r, eval=FALSE, getstats} get_report(ids = "channel==MINE", metrics = "views", start_date = "2010-04-01", end_date ="2017-04-01") ``` ``` ## $kind ## [1] "youtubeAnalytics#resultTable" ## $columnHeaders ## $columnHeaders[[1]] ## $columnHeaders[[1]]$name ## [1] "views" ## $columnHeaders[[1]]$columnType ## [1] "METRIC" ## $columnHeaders[[1]]$dataType ## [1] "INTEGER" ## $rows ## $rows[[1]] ## $rows[[1]][[1]] ## [1] 6 ```