Regarding accessing youtube watch history using App Script

409 views
Skip to first unread message

Harsh Chaudhary

unread,
Dec 7, 2022, 11:38:10 PM12/7/22
to Google Apps Script Community
Hi all,

I am wondering how I could access my watch history of Youtube using AppScript. I also referred through document, but didn't find as such helpful material.

If anyone has any idea or has worked in this area, do let me know how to achieve the task.

Thanks.

cwl...@gmail.com

unread,
Dec 10, 2022, 1:00:00 PM12/10/22
to Google Apps Script Community
See if this works. Provided by ChatGPT. (https://chat.openai.com/chat)

Q:  how I could access my watch history of Youtube using AppScript
A: 

To access your watch history on YouTube using AppScript, you will first need to enable the YouTube Data API for your Google account. You can do this by following these steps:

  1. Go to the Google Cloud Console and log in with your Google account.
  2. Click on the "Select a project" dropdown at the top of the page, and then click on the "Create project" button.
  3. Enter a name for your project and click on the "Create" button.
  4. Once your project has been created, click on the "ENABLE APIS AND SERVICES" button.
  5. In the search box, type "YouTube Data API" and click on the "YouTube Data API" result that appears.
  6. Click on the "ENABLE" button to enable the YouTube Data API for your project.

Once you have enabled the YouTube Data API, you can use the following code in your AppScript project to access your watch history:

function getWatchHistory() {
  var youtube = YouTube.newService();
  var channel = youtube.channels.list('contentDetails', {mine: true});
  var channelId = channel.items[0].id;
  var playlist = youtube.playlistItems.list('id, contentDetails', {playlistId: channelId, maxResults: 50});
  var watchHistory = [];
  for (var i = 0; i < playlist.items.length; i++) {
    var videoId = playlist.items[i].contentDetails.videoId;
    var video = youtube.videos.list('snippet, contentDetails', {id: videoId});
    watchHistory.push(video.items[0]);
  }
  return watchHistory;
}

This code uses the YouTube Data API to retrieve the list of videos in your watch history. It returns an array of video objects, each of which contains information about a video in your watch history (e.g., title, description, duration, etc.). You can then use this information to display your watch history in your AppScript project.

Cornelia Davis

unread,
Feb 5, 2023, 7:14:38 PM2/5/23
to Google Apps Script Community
ChatGPT apparently does not know that the watch history API has been deprecated (way back in 2017).
Reply all
Reply to author
Forward
0 new messages