Skip to content

Commit

Permalink
fix get_playlist_items (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
thieled authored Apr 10, 2024
1 parent 7acfa93 commit 774a6f2
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions R/get_playlist_items.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ get_playlist_items <- function(filter = NULL, part = "contentDetails",
pageToken = page_token, videoId = video_id)
querylist <- c(querylist, filter)

res <- tuber_GET("playlistItems", querylist, ...)
res <- tuber_GET(path = "playlistItems",
query = querylist,
...)

if (max_results > 50) {
page_token <- res$nextPageToken
while (is.character(page_token)) {
a_res <- tuber_GET("playlistItems", list(
part = part,
playlistId = unname(filter["playlistId"]),
maxResults = 50,
pageToken = page_token
))
a_res <- tuber_GET(path = "playlistItems",
query = list(
part = part,
playlistId = unname(filter[["playlistId"]]), ## <--- double brackets
maxResults = 50,
pageToken = page_token
),
...) ## <--- pass arguments to tuber_GET
res <- c(res, a_res)
page_token <- a_res$nextPageToken
}
Expand All @@ -82,14 +86,14 @@ get_playlist_items <- function(filter = NULL, part = "contentDetails",
allResultsList <- lapply(allResultsList, unlist)
res <-
do.call(
rbind.fill,
plyr::rbind.fill,
lapply(
allResultsList,
function(x) as.data.frame(t(x), stringsAsFactors = FALSE)
)
)
}

res
return(res)
}

0 comments on commit 774a6f2

Please sign in to comment.