Google脚本中是否有每分钟脚本触发器出现问题?
下面是一个为单个视频提取YT数据并写入电子表格的功能,我们在发布视频时会运行一小时。
每分钟触发器工作正常,现在它停止工作。
如果有人有任何想法,欢迎他们!
function STATSScript() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Generator");
var sheets = ss.getSheets();
// if (sheets.length > 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 + '&key=' + apiKey + '&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 > 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);
}
答案 0 :(得分:-2)
这很简单,你只有有限的时间,所以每分钟运行它会让你跑得太多。 登录您的Google帐户,查看每日配额使用情况。
详情请见此处: https://developers.google.com/apps-script/guides/services/quotas 通过使用Google脚本,您可以制作按照计划运行的程序。
Google表示,您无法在一天内多次调用多次功能。配额链接告诉了多少,这也取决于您是使用免费版还是您是否付费。 因此,如果脚本运行很长时间或很短的时间,您必须通过最大每日运行量。