问题
Today is the first day I ever tried to do anything with an API. I wanted to get the duration of all the videos of a channel added together. Because the channel I am interested in has 23708 videos I first tried my code with a smaller channel to make sure that it does what I want it to do, which it did. I used a simple counter variable to be able to see whether every video was used and the number was equal to the number I was expecting based on the channel infos. But when I tried it with the bigger channel the counter only went up to 20000, instead of 23708 (which is the number of videos on the channel) and I can't figure out why. The code here is just the trying to go through all videos stuff without the calculation parts which is why the counter only counts the number of pages it goes through instead of each video (It goes up to 20000/50 = 400 in this case). The playlistId is the ID of the Uploads playlist of the channel.
nextPageToken = None
while True:
v_request = youtube.playlistItems().list(
part = 'id',
playlistId='UUqwGaUvq_l0RKszeHhZ5leA',
maxResults = 50,
pageToken = nextPageToken
)
response = v_request.execute()
counter += 1
nextPageToken = response.get('nextPageToken')
if not nextPageToken:
break
回答1:
According to YouTube's staff, there's an upper 20000 limit set by design for the number of items returned via PlaylistItems.list
endpoint when queried for a given channel's uploads playlist. This is unfortunate, but a fact.
You may also take into account the recommendation I made responding to a similar question.
来源:https://stackoverflow.com/questions/64878654/is-there-a-maximum-number-of-videos-in-an-uploads-playlist-to-iterate-through