首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Google脚本插入YouTube顶级注释

使用Google脚本插入YouTube顶级注释
EN

Stack Overflow用户
提问于 2018-06-24 18:38:35
回答 2查看 451关注 0票数 3

我正在尝试创建一个使用Google脚本的程序,在某个YouTube频道上传时插入评论。我已经能够从频道获得最新的YouTube视频ID,但是当我尝试插入一个注释时,它会抛出一个错误,"Parse (第19行,文件'Code')“。

第19行:YouTube.CommentThreads.insert("snippet", {

这是我的密码:

代码语言:javascript
复制
function getVideo() {
  // MrBeast Channel ID: UCX6OQ3DkcsbYNE6H8uQQuVA
  var channel = "UCX6OQ3DkcsbYNE6H8uQQuVA";
  var fttx = "FIRST!";
  var results = YouTube.Channels.list("contentDetails", {"id": channel});
  for (var i in results.items) {
    var item = results.items[i];
    var playlistId = item.contentDetails.relatedPlaylists.uploads;
    // Uploads Playlist ID: UUX6OQ3DkcsbYNE6H8uQQuVA
    var playlistResponse = YouTube.PlaylistItems.list("snippet", {"playlistId": playlistId, "maxResults": 1});
    for (var j = 0; j < playlistResponse.items.length; j++) {
      var playlistItem = playlistResponse.items[j];
      var latvid = playlistItem.snippet.resourceId.videoId;
      comment(latvid, channel, fttx);
    }
  }
}
function comment(vid, ytch, fc) {
  YouTube.CommentThreads.insert("snippet", {
    "snippet.channelId": ytch,
    "snippet.videoId": vid,
    "snippet.topLevelComment.snippet.textOriginal": fc
  });
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-26 04:05:13

方法的参数。如果使用Apps脚本编辑器的“自动完成”,则非常清楚所需的顺序:

还请注意,您错误地创建了您的资源主体-您有各种子属性。例如,snippet属性是资源的必需成员。三个"snippet.___"属性不等同于一个具有3个子属性的snippet属性。

因此,解决YouTube.CommentThreads.insert中的解析错误的解决方案是使用必需的方法签名,并使用所需的资源格式:

代码语言:javascript
复制
function startCommentThread(vid, ytch, fc) {
  const resource = {
    snippet: {
      channelId: ytch,
      videoId: vid,
      topLevelComment: {
        snippet: {
          textOriginal: fc
        }
      }
    }
  };
  YouTube.CommentThreads.insert(resource, "snippet");
}
票数 2
EN

Stack Overflow用户

发布于 2018-06-26 03:40:49

根据文档,{}缺失并使用单引号。我现在不能测试这个,但希望它能解决你的问题。

代码语言:javascript
复制
  commentThreadsInsert('snippet',
      {},
      {'snippet.channelId': '',
       'snippet.videoId': '',
       'snippet.topLevelComment.snippet.textOriginal': ''
      });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51012865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档