Giter VIP home page Giter VIP logo

ytr's Introduction

ytr

R wrapper to the YouTube Analytics API.

Install

# install.packages("remotes")
remotes::install_github("JohnCoene/ytr")

Functions

  • ytr_oauth - Authenticate
  • ytr_reports - Get data
  • ytr_parse - Parse results

Setup

Create a free application in the Google Console to obtain your client and secret.

# OAuth
token <- ytr_oauth("something.apps.googleusercontent.com",
    "xxXx0X0x0X0xXX0")

Examples

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()
#> # A tibble: 1 x 2
#>   views likes
#>   <int> <int>
#> 1 24597   237

# 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()
#> # A tibble: 10 x 5
#>    video       estimatedMinutesWatched views likes subscribersGained
#>    <chr>                         <int> <int> <int>             <int>
#>  1 x2l7KscqRro                   49113 20269   128               185
#>  2 cFhONVldyE0                   37664  6455    96                80
#>  3 WsQ7ysVt-0A                   82857  8260   103                77
#>  4 8vnI5JBBFhU                   40635  5378    37                32
#>  5 4zzVjonyHcQ                   44922  3230    25                31
#>  6 c26OV713-Do                   48037  2469    26                29
#>  7 kpW9JcWxKq0                   10235  2313    17                25
#>  8 Pd8YY-IokMs                   17748  3012    16                18
#>  9 1O3ghiyirvU                   21104  1529    21                16
#> 10 -OiaE6l8ysg                    6944  1508    23                15

# 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()
#> # A tibble: 2 x 5
#>   video       estimatedMinutesWatched views likes subscribersGained
#>   <chr>                         <int> <int> <int>             <int>
#> 1 x2l7KscqRro                   49113 20269   128               185
#> 2 cFhONVldyE0                   37664  6455    96                80

ytr's People

Contributors

johncoene avatar jpcoene avatar

Stargazers

 avatar Romain Lesur avatar Artem Klevtsov avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

ytr's Issues

Error when i send query with out one of arguments.

Hello, thk for package.

All works if I send next query:

token %>% 
  ytr_reports() %>% 
  ytr_parse()

And

token %>% 
  ytr_reports(
    start = Sys.Date() - 7,
    metrics = c("estimatedMinutesWatched","views","likes","subscribersGained"), 
    dimensions = "video", 
    maxResults = 100, 
    sort = "-subscribersGained"
  ) %>% 
  ytr_parse()

But if i excluded one if arguments i get next error:

reprex:

library(ytr)
library(magrittr)

(

token %>% 
  ytr_reports(
    start = Sys.Date() - 7,
    metrics = c("estimatedMinutesWatched","views","likes","subscribersGained"), 
    dimensions = "video", 
    maxResults = 100
  ) %>% 
  ytr_parse())
#> Error in ytr_reports(., start = Sys.Date() - 7, metrics = c("estimatedMinutesWatched", : Bad Request (HTTP 400).

Created on 2019-06-24 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.0 (2019-04-26)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Russian_Russia.1251         
#>  ctype    Russian_Russia.1251         
#>  tz       Europe/Helsinki             
#>  date     2019-06-24                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source                         
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                 
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.6.0)                 
#>  callr         3.2.0      2019-03-15 [1] CRAN (R 3.6.0)                 
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)                 
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                 
#>  curl          3.3        2019-01-10 [1] CRAN (R 3.6.0)                 
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                 
#>  devtools      2.0.2.9000 2019-06-19 [1] Github (r-lib/devtools@8c97dee)
#>  digest        0.6.19     2019-05-20 [1] CRAN (R 3.6.0)                 
#>  evaluate      0.13       2019-02-12 [1] CRAN (R 3.6.0)                 
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                 
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)                 
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                 
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.0)                 
#>  httr          1.4.0      2018-12-11 [1] CRAN (R 3.6.0)                 
#>  knitr         1.23       2019-05-18 [1] CRAN (R 3.6.0)                 
#>  magrittr    * 1.5        2014-11-22 [1] CRAN (R 3.6.0)                 
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                 
#>  pkgbuild      1.0.3      2019-03-20 [1] CRAN (R 3.6.0)                 
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)                 
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)                 
#>  processx      3.3.1      2019-05-08 [1] CRAN (R 3.6.0)                 
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                 
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                 
#>  Rcpp          1.0.1      2019-03-17 [1] CRAN (R 3.6.0)                 
#>  remotes       2.0.4      2019-04-10 [1] CRAN (R 3.6.0)                 
#>  rlang         0.3.4      2019-04-07 [1] CRAN (R 3.6.0)                 
#>  rmarkdown     1.12       2019-03-14 [1] CRAN (R 3.6.0)                 
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                 
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                 
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                 
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                 
#>  testthat      2.1.1      2019-04-23 [1] CRAN (R 3.6.0)                 
#>  usethis       1.5.0      2019-04-07 [1] CRAN (R 3.6.0)                 
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                 
#>  xfun          0.7        2019-05-14 [1] CRAN (R 3.6.0)                 
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)                 
#>  ytr         * 0.0.1      2019-06-24 [1] Github (JohnCoene/ytr@cfc1bce) 
#> 
#> [1] D:/r_library
#> [2] C:/Program Files/R/R-3.6.0/library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.