Home > Back-end >  Google Sheets YouTube API Published Date Issue
Google Sheets YouTube API Published Date Issue

Time:09-17

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"];
}

CodePudding user response:

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