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:
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;
}