How to get a user's entire YouTube watch history?

Fsmv picture Fsmv · May 15, 2013 · Viewed 27.4k times · Source

I'm trying to get a full list of watched videos for a given user in my YouTube API application. I want to add up total duration of all videos.

When I get the list of videos from history playlist, the API caps it at 50 items. There's pagination but total amount of items is 50 (not just per page); I can't access more data with the API it appears.

Is there any way I can get this playlist without the data cap? I'm hoping for another method (of using the API) or a way to do it without the API. I know YouTube stores this data because I can view my entire history (far more that 50 videos).

I'm using this code:

var requestOptions = {
    playlistId: playlistId,
    part: 'snippet',
    maxResults: 50
};
gapi.client.youtube.playlistItems.list(requestOptions);

where playlistId is the id of the history playlist I got from a gapi.client.youtube.channels.list request.

Edit (2017): I want to clarify that it was always my intention to download my own history, just out of interest to see how much time I have spent watching videos. I still have not been able to do this.

Answer

vol7ron picture vol7ron · Jul 16, 2015

The API currently only retrieves the last two weeks of Watch History. For more information refer to the Bug Issue reported: https://code.google.com/p/gdata-issues/issues/detail?id=4642

Note: There is a similar question on SO asked here: YouTube API v3 returns truncated watch history