1

I want to get the Users watch history of YouTube. This is what I have so far:

function readLatestMovies() {
  var results = YouTube.Channels.list('contentDetails', {mine: true});
  Logger.log(results);
}

In the logger I get the following response:

[16-04-21 20:01:17:467 CEST] {kind=youtube#channelListResponse, pageInfo={totalResults=1, resultsPerPage=1}, etag="dj7Wjtujr8JpxjNVWXy19qVsBRI/9D_cSFBT_DW00BBlOmm4X-jyEHU", items=[{kind=youtube#channel, etag="dj7Wjtujr8JpxjNVWXy19qVsBRI/A_CrD02UoyPA7qPATfqaeKRauW4", id=UCUI8-QMlqUsrpDB9ECPXZng, contentDetails={relatedPlaylists={favorites=FLUI8-QMlqUsrpDB9ECPXZng, watchHistory=HLUI8-QMlqUsrpDB9ECPXZng, watchLater=WLUI8-QMlqUsrpDB9ECPXZng, uploads=UUUI8-QMlqUsrpDB9ECPXZng, likes=LLUI8-QMlqUsrpDB9ECPXZng}}}]}

So there is the watchHistory=HLUI8-QMlqUsrpDB9ECPXZng. So my question is: how do I ACTUALLY get the history that seems to be hidden in the variable results?

Thanks a lot in advance!

1

1 Answer 1

2

The id HLUI8-QMlqUsrpDB9ECPXZng is a playlistId. To get the history of your channel you need two step :

First, get the playlistId with resource channel.list like you did :

function readLatestMovies() {

  var results = YouTube.Channels.list('contentDetails', {mine: true});
  Logger.log(results);

}

More infos : https://developers.google.com/youtube/v3/docs/channels/list

Second, use the ressource playlistItems.list to get all the videos from the playlist

function PLaylistHistory() {
  var results = YouTube.PlaylistItems.list('snippet', {playlistId: 'HLUI8-QMlqUsrpDB9ECPXZng'});
  Logger.log(results);
}

More infos : https://developers.google.com/youtube/v3/docs/playlistItems/list

Of course you need to be authenticated to get this playlist :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.