GIVEN a channel ID (mine) , return total number of playlists.

knitr::opts_chunk$set(echo = TRUE,  
                      comment="      ##",  
                      error=TRUE, 
                      collapse=TRUE)
load_all()
#  docs:  https://developers.google.com/youtube/v3/docs/playlists
api <- get_api_codes()
if (!exists("l")) l  <- get_typical_values()
base_url <- "https://www.googleapis.com/youtube/v3/playlists"

Auth_code - this a bad hack, till I understand tokens

auth.code  <- readRDS(".httr-oauth")[[1]]
auth.code

get_playlists_count()

#'  @title get_playlists_count
#'  @description Given query (with channelId), return the number of playlists

query  <- list(
  part="snippet",
    channelId="UClB5qWyXejlAwwkDAzJis-Q",
  #mine = 'true',
    max_results=5,
  fields="pageInfo(totalResults)",
    key=api$api_key
    )
r  <- httr::GET(url = base_url,
                            query= query,
                            config = httr::config(token = auth.code)
                            )

r  <- httr::GET(url = base_url,
                            query= query
                            )
r
httr::stop_for_status(r)

json_content  <- get_json(r)
count  <- json_content$pageInfo$totalResults
count #  ~157,  16 is too low
r  <- httr::HEAD(url = base_url,
                            query= query,
                            config = httr::config(token = auth.code)
                            ) 
r
knitr::knit_exit()
# TODO:  file is found when knitr runs (see above)

# file must be of form:
# dir/name_of_this_file    where dir is relative to project root

file  <- "rmd/010_playlists.Rmd"

# in general, pdf will look nicer
rmarkdown::render(file,
                  #output_format = "pdf_document",
                  output_format = "html_document",
                  output_file = "~/Downloads/print_and_delete/out")


jimrothstein/yt_api documentation built on Nov. 5, 2022, 8:05 p.m.