Cannot page through all results using nextPageToke

2019-07-13 05:51发布

问题:

I am using the YouTube search API v3. I am trying to get snippets of all the videos of a channel. To go from page to page, I use the nextPageToken. The channel that I am interested in has 3,628 total results. After I get to 500 videos (the 10th page, as I am requesting 50 videos per page), the nextPageToken is no longer passed back.

Is there a limit on the total number of videos I can page through for a particular channel?

Initially, I start off with the following URL and follow the nextPageToken by appending to the query string &pageToken=[nextPageToken].

https://www.googleapis.com/youtube/v3/search?key=[key]&channelId=UCEBb1b_L6zDS3xTUrIALZOw&part=snippet,id&order=date&maxResults=50&safeSearch=none&videoEmbeddable=true&type=video

The URL for the 10th page is as follows.

https://www.googleapis.com/youtube/v3/search?key=[key]&channelId=UCEBb1b_L6zDS3xTUrIALZOw&part=snippet,id&order=relevance&maxResults=50&safeSearch=none&videoEmbeddable=true&type=video&pageToken=CMIDEAA

Also, I note something weird in that from page to page, the total number of videos changes. Is this a known bug?

The following table list the page along with the corresponding page token and total results. Note that I do not (need to) pass in a pageToken for the first page.

+------+------------+---------------+
| Page | Page Token | Total Results |
+------+------------+---------------+
|    1 | [none]     |          3628 |
|    2 | CDIQAA     |          3628 |
|    3 | CGQQAA     |          3626 |
|    4 | CJYBEAA    |          3626 |
|    5 | CMgBEAA    |          3625 |
|    6 | CPoBEAA    |          3625 |
|    7 | CKwCEAA    |          3625 |
|    8 | CN4CEAA    |          3624 |
|    9 | CJADEAA    |          3624 |
|   10 | CMIDEAA    |          3624 |
+------+------------+---------------+

回答1:

Maybe you want to use PlaylistItem instead of Search. It is much cheaper according to quota (100 vs 6) and gives up to 100.000 Videos for a given playlist. Every channel has got a uploads-playlist, in which all uploaded videos are stored.

For more details, watch: https://www.youtube.com/watch?v=RjUlmco7v2M