Google Sheets YouTube API Published Date Issue

Viewed 27

I have a google sheet setup for pulling YouTube API information like duration, title, etc. However I'm struggling to get the function working for the video date.

does anyone have any advice?

function getYoutubeDate(videoId){
  var url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + videoId;
  url = url + key;
  var videoListResponse = UrlFetchApp.fetch(url);
  var json = JSON.parse(videoListResponse.getContentText());
  return json["items"][0]["snippet"]["publishedAt"];
}
1 Answers

You need to add the snippet part in your request:

Change:

var url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + videoId;

To:

var url = "https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=" + videoId;
Related