问题描述
我可以通过 YouTube v3 数据 API 访问我的观看历史记录,但它只返回我最近的 30 个视频(尽管我在 YouTube.com 上查看观看历史记录时会看到更多视频).
I'm able to access my watch history via the YouTube v3 data API, but it only returns my most recent 30 videos (though I see many more when I view the Watch History on YouTube.com).
然后当我看另一个视频时,它返回31.当我看另一个时,32.如果它可以返回超过30,为什么它原来没有返回更多?我知道 API 可能有限制,但为什么从 30 开始然后增长呢?有了分页,真的不应该有限制,对吧?
And then when I watch another video, it returns 31. When I watch another, 32. If it can return more than 30, why didn't it return more originally? I understand that the API might have a limit, but why start at 30 then grow? And with paging, there really shouldn't be a limit, right?
我一定是做错了什么.这是我的代码:
I must be doing something wrong. Here's my code:
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()
results = []
for x in playlistItems_response["items"]:
videoTitle = x["snippet"]["title"]
videoId = x["contentDetails"]["videoId"]
videoSpec = videoId + ": " + videoTitle
print 'adding to results: ' + videoSpec
results.append(videoSpec)
if ("nextPageToken" in playlistItems_response):
pageToken = playlistItems_response["nextPageToken"]
results.extend(retrieveVideos(youtube, playlistId, pageToken));
return results
else:
return results
推荐答案
更新:自 2016 年 9 月 15 日起,watchHistory 不再以任何身份提供,因此很遗憾,现在已无关紧要.
这似乎是 2013 年最初报告的已知错误.在 Google 代码线程中解释了完全相同的行为:https://code.google.com/p/gdata-issues/issues/detail?id=4642
我得到了结果,但就像一些海报一样,它们是最近的视频(可能是一天的价值).我似乎找不到任何关于检索时间限制的文档.任何人都找到了解决方法或想通了历史可用多长时间?"(最近对该主题的评论)
"I get back results but like a few posters up, they are very recent videos (possibly a day's worth). I can't seem to find any documentation on a time limit for retrieval. Anybody found a workaround or figured out how long the history is available?" (recent comment on the thread)
在 Google 决定解决此问题之前,我似乎很不走运.希望有人证明我(以及该 Google 代码线程中的其他人)是错误的.
Looks like I'm out of luck until Google decides to fix this. Hopefully someone proves me (and everone else in that Google Code thread) wrong.
这篇关于YouTube API v3 返回截断的观看记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!