我可以通过 YouTube v3 数据 API 访问我的观看历史记录,但它只返回我最近的 30 个视频(尽管当我在 YouTube.com 上查看观看历史记录时我会看到更多)。
然后当我看另一个视频时,它返回31。当我看另一个视频时,它返回32。如果它可以返回超过30,为什么它最初不返回更多?我知道 API 可能有限制,但为什么从 30 开始然后逐渐增长呢?对于分页来说,确实不应该有限制,对吗?
我一定做错了什么。这是我的代码:
def getWatchHistory(youtube):
playlistId = getWatchHistoryPlaylistId(youtube)
videos = retrieveVideos(youtube, playlistId);
return videos # Only returns 30, 31, 32 videos, etc. though I have many more in my History
def getWatchHistoryPlaylistId(youtube):
channels_response = youtube.channels().list(
part="contentDetails",
mine=True,
).execute()
channel = channels_response["items"][0]
playlistId = channel["contentDetails"]["relatedPlaylists"]["watchHistory"]
return playlistId
def retrieveVideos(youtube, playlistId, nextPageToken=None):
# Search the specified playlist and list all videos
playlistItems_response = youtube.playlistItems().list(
part="snippet,contentDetails",
playlistId=playlistId,
maxResults=50,
pageToken=nextPageToken
).execute() …Run Code Online (Sandbox Code Playgroud)