title: Google Script Every Minute Trigger
body: <p>Anybody having problems with the every minute script trigger in Google scripts?</p>
  
  <p>Below is a function to pull YT data for a single video and write to a spreadsheet, which we run for an hour when we publish a video.</p>
  
  <p>The every minute trigger used to work fine, and now it stopped working.</p>
  
  <p>If anybody has any thoughts they would be welcome!</p>
  
  <pre><code>function STATSScript() {
  
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
  //  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Generator");
    var sheets = ss.getSheets();
  
  //   if (sheets.length &gt; 1) {
  //     Logger.log(sheets[0].getName());
   //  Logger.log(sheets[1].getName());
       //Logger.log(sheets[2].getName());
  // }
  
  //  var sheet = ss.getSheetByName("Generator"); //or whatever you name your sheet
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Generator");
    var apiKey = 'KEY'; //leave the single quotes
    var vidId = sheet.getRange("c3").getValue(); 
   // Logger.log(ss);
  
    var url = 'https://www.googleapis.com/youtube/v3/videos?id=' + vidId + '&amp;key=' + apiKey + '&amp;part=snippet,contentDetails,statistics,status'; // replace this with your API client ID
    //take a look at the raw JSON for this request at https://www.googleapis.com/youtube/v3/videos?id=ID=snippet,contentDetails,statistics,status
    var currentTime = new Date();
  
    var response = UrlFetchApp.fetch(url); // get feed
    var json = response.getContentText(); // 
    var data = JSON.parse(json);
    //  Logger.log(data);
    var stats = [];
  
  
      stats.push(data.items[0].snippet.title); //video title
  
    //    Logger.log(data.items[0].snippet.title);
  
      stats.push(data.items[0].statistics.viewCount); //view count
      stats.push(data.items[0].statistics.likeCount); //like count
      stats.push(data.items[0].statistics.dislikeCount); //dislike count
  
      stats.push(data.items[0].statistics.commentCount); //comment count
  
      stats.push(data.items[0].snippet.publishedAt); //publish date
      stats.push(data.items[0].snippet.channelTitle); //title of the channel or user
      stats.push("https://www.youtube.com/watch?v="+vidId); //link
      stats.push(currentTime); //time script ran
  
      SpreadsheetApp.getActiveSheet().appendRow(stats)
  
    Logger.log(stats);
    Logger.log("Row Data Written");
  
  }
  
  
  
  // -----------------------------------------------------------------------------
  // function to clear data
  // -----------------------------------------------------------------------------
  function clearData() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName('Generator');
  
    sheet.getRange("A2:A3").clearContent();
  
    // clear out the matches and output sheets
    var lastRow = sheet.getLastRow();
    if (lastRow &gt; 1) {
      sheet.getRange(5,1,lastRow-1,9).clearContent();
    }
      Logger.log("Data Cleared");
  }
  
  
  
  function archiveSheet () {
  //Archive the Sheet
     var sheet = SpreadsheetApp.getActiveSpreadsheet();
     var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheets = ss.getSheets();
     var lastrow = sheet.getLastRow();
     var range = sheet.getRange('A1:N' + (lastrow) + '');
     var date = new Date();
     var formattedDate = Utilities.formatDate(date, "CST", "MM-dd-yy")
     var titleofvid = ss.getRange("a3").getValue(); 
    var titlefilename = formattedDate+' '+titleofvid;
     sheet.setNamedRange('Archive', range);
     var TestRange = sheet.getRangeByName('Archive').getValues(); 
     Logger.log(TestRange); 
     var destFolder = DriveApp.getFolderById('ID'); 
     DriveApp.getFileById(sheet.getId()).makeCopy(titlefilename, destFolder);   
  }
  
  function cloneGoogleSheet() {
  
    var source = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = source.getSheets()[0];
    var destination = SpreadsheetApp.openById('ID');
  
   sheet.copyTo(destination);
  
  }
  </code></pre>