【问题标题】:Google Script - Auto add recently uploaded YT videos from subscriptions to specific playlistsGoogle Script - 自动将最近上传的 YOUTUBE 视频从订阅中添加到特定播放列表
【发布时间】:2018-07-29 18:12:49
【问题描述】:

我在 github 上找到的 google 脚本有点麻烦。 原文代码:https://github.com/Elijas/auto-youtube-subscription-playlist-2

此脚本的作用:

您将在 youtube 上订阅的频道 ID 添加到 Google 电子表格中,并将它们引用到您希望添加新视频的播放列表 ID:

Spreadsheet Screenshot

我的问题是:

只要我打开电子表格并手动执行“updatePlaylists”功能,脚本本身就可以正常工作。

但是一旦我添加了一个时间驱动的触发器(或尝试在脚本编辑器中执行该函数),脚本就会一直失败:

TypeError: Cannot call method "toString" of undefined.

但我在互联网上找到了针对该特定错误的“修复”。所以我把这个特定的代码行改为:

if (typeof sheet === 'undefined') sheet = SpreadsheetApp.openById('MY_GOOGLE_SHEET_ID').getSheets

但现在我收到以下错误:

"TypeError: Cannot find function getDataRange in object [object Object]. (Row 18, File "Code")"

这将是这部分代码:

Cannot find function getDataRange in object [object Object]

由于脚本似乎工作,只要我从电子表格中执行它,我想它一定与脚本中的“工作表”变量有关。但是由于我对谷歌的脚本语言不是很熟悉,所以我真的希望这里有人可以帮助我解决这个问题。

任何想法将不胜感激:)

编辑:根据 Chris 的要求,我将在此处发布部分代码。我只是不想粘贴整个脚本,因为它很大。我希望这已经足够了。如果没有,您可以立即从here 下载整个脚本。

function updatePlaylists(sheet) {
  if (typeof sheet === 'undefined') sheet = SpreadsheetApp.openById('1Jj1Sx0mvfCKfYFcfX4karP9ztPgkyURj3pBvOExsljQ').getSheets()[0]; // Hotfix, Paste the Sheet ID here, it's the long string in the Sheet URL
  var data = sheet.getDataRange().getValues();
  var reservedTableRows = 3; // Start of the range of the PlaylistID+ChannelID data
  var reservedTableColumns = 2; // Start of the range of the ChannelID data
  var reservedTimestampCell = "F1";
  //if (!sheet.getRange(reservedTimestampCell).getValue()) sheet.getRange(reservedTimestampCell).setValue(ISODateString(new Date()));
  if (!sheet.getRange(reservedTimestampCell).getValue()) {
    var date = new Date();
    date.setHours(date.getHours() - 24); // Subscriptions added starting with the last day
    var isodate = date.toISOString();
    sheet.getRange(reservedTimestampCell).setValue(isodate);
  }

【问题讨论】:

  • 你能贴出代码而不是代码的图片吗?如果我们可以复制和粘贴,帮助解决问题会更容易。
  • 您更改的行不是原始功能的一部分 - 它是由另一个贡献者添加的,可能已经破坏了一些东西 (?)。您可以尝试在合并之前将其与此处的原始代码进行比较,例如github.com/Elijas/auto-youtube-subscription-playlist-2/blob/… 因为当我尝试手动运行“updatePlaylists”功能时,这段代码运行良好(我是谷歌脚本的原始创建者)。
  • Ok thx,我今晚会测试它,并会在这里给出反馈。非常感谢你的辛勤工作。这个脚本真的很棒!

标签: google-apps-script youtube-data-api


【解决方案1】:

感谢脚本原作者普罗米修斯的回复,我终于能够解决问题了。 显然,“updatePlaylists”功能已由 github 上的贡献者编辑。

遇到同样问题的每个人,都这样做:

只需将 Code.gs 中的“updatePlalists”函数替换为原始版本即可:

function updatePlaylists() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  var data = sheet.getDataRange().getValues();
  var reservedTableRows = 3; // Start of the range of the PlaylistID+ChannelID data
  var reservedTableColumns = 2; // Start of the range of the ChannelID data
  var reservedTimestampCell = "F1";
  //if (!sheet.getRange(reservedTimestampCell).getValue()) sheet.getRange(reservedTimestampCell).setValue(ISODateString(new Date()));
  if (!sheet.getRange(reservedTimestampCell).getValue()) {
    var date = new Date();
    date.setHours(date.getHours() - 24); // Subscriptions added starting with the last day
    var isodate = date.toISOString();
    sheet.getRange(reservedTimestampCell).setValue(isodate);
  }

【讨论】:

  • 很高兴它再次工作!在官方 README 中为其他人提到了您的解决方案。
猜你喜欢
  • 2016-06-06
  • 2019-06-13
  • 2021-01-16
  • 1970-01-01
  • 2017-03-23
  • 2018-03-10
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
相关资源
最近更新 更多