Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'get_playlist_items' pagination not passing arguments to tuber_GET #132

Open
thieled opened this issue Apr 10, 2024 · 0 comments
Open

'get_playlist_items' pagination not passing arguments to tuber_GET #132

thieled opened this issue Apr 10, 2024 · 0 comments

Comments

@thieled
Copy link
Contributor

thieled commented Apr 10, 2024

'get_playlist_items' breaks when using a API key for authentication (auth = "key"), instead of a token.

Here is a example that works:

sub50 <-  tuber::get_playlist_items(filter = list(playlist_id = "UURWBzDUKfaNmK_FwtDMgyqg"),
                            max_results = 50,
                            simplify = T,
                            auth = "key")
head(sub50)

Output:

> head(sub50)  
                  kind                        etag                                               id contentDetails.videoId contentDetails.videoPublishedAt
1 youtube#playlistItem iRfjrBJEC5ZCvhP8_tSYOl795cA VVVSV0J6RFVLZmFObUtfRnd0RE1neXFnLngtTDFyNmVCVzYw            x-L1r6eBW60            2024-04-04T16:06:50Z
2 youtube#playlistItem GbmPMsG9F3tv9op5UB9Zcmv29Fc VVVSV0J6RFVLZmFObUtfRnd0RE1neXFnLkJ6c3lqQ1NfeW53            BzsyjCS_ynw            2024-03-10T20:00:13Z
3 youtube#playlistItem sPMURCcfFgDGkyBeeqhG8c39WA4 VVVSV0J6RFVLZmFObUtfRnd0RE1neXFnLlRfTkhSMWRGNGMw            T_NHR1dF4c0            2024-02-05T19:56:20Z
4 youtube#playlistItem Sx0ByF99fh8DOyrFk04ayL_ZJAo VVVSV0J6RFVLZmFObUtfRnd0RE1neXFnLkV0Z01VU1hLczJZ            EtgMUSXKs2Y            2022-12-30T12:10:45Z
5 youtube#playlistItem JSkl_CwzTqwfFmZmWEx80xzWELE VVVSV0J6RFVLZmFObUtfRnd0RE1neXFnLnBvQ3p5Tmc0UFc4            poCzyNg4PW8            2022-12-21T17:00:10Z
6 youtube#playlistItem BUM6A5oIUxWDCQqA1T-ZjVuweTM VVVSV0J6RFVLZmFObUtfRnd0RE1neXFnLnMzazRiTFlsdFZj            s3k4bLYltVc            2022-12-08T12:59:38Z


This does not work:

plus50 <-  tuber::get_playlist_items(filter = list(playlist_id = "UURWBzDUKfaNmK_FwtDMgyqg"),
                                    max_results = 51,
                                    simplify = T,
                                    auth = "key")

Error:

Error in yt_check_token() : Please get a token using yt_oauth().

The reason for this is a missin ... in the pagination handling in the function get_playlist_items:

  res <- tuber_GET("playlistItems", 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
      ))
      res <- c(res, a_res)
      page_token <- a_res$nextPageToken
    }
  }

Should be:

  res <- tuber_GET("playlistItems", 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
      ), ...) # <------------------
      res <- c(res, a_res)
      page_token <- a_res$nextPageToken
    }
  }

I'll send you a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant