Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 使用谷歌应用程序脚本插入YouTube顶级评论_Google Apps Script_Youtube Data Api - Fatal编程技术网

Google apps script 使用谷歌应用程序脚本插入YouTube顶级评论

Google apps script 使用谷歌应用程序脚本插入YouTube顶级评论,google-apps-script,youtube-data-api,Google Apps Script,Youtube Data Api,我试图创建一个程序,使用谷歌应用程序脚本,在某个YouTube频道上传时插入评论。我已经能够从该频道获得最新的YouTube视频ID,但当我尝试插入评论时,它抛出了一个错误,“解析错误(第19行,文件“代码”) 第19行:YouTube.CommentThreads.insert(“snippet”,{ 这是我的密码: function getVideo() { // MrBeast Channel ID: UCX6OQ3DkcsbYNE6H8uQQuVA var channel = "

我试图创建一个程序,使用谷歌应用程序脚本,在某个YouTube频道上传时插入评论。我已经能够从该频道获得最新的YouTube视频ID,但当我尝试插入评论时,它抛出了一个错误,“解析错误(第19行,文件“代码”)

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

这是我的密码:

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
  });
}
函数getVideo(){ //MrBeast通道ID:UCX6OQ3DkcsbYNE6H8uQQuVA var channel=“UCX6OQ3DkcsbYNE6H8uQQuVA”; var fttx=“第一!”; var results=YouTube.Channels.list(“contentDetails”,{“id”:channel}); 对于(results.items中的var i){ var项目=结果。项目[i]; var playlaid=item.contentDetails.relatedPlaylists.uploads; //上载播放列表ID:UUX6OQ3DkcsbYNE6H8uQQuVA var playlayresponse=YouTube.playlitems.list(“snippet”,{“playlyid”:playlyid,“maxResults”:1}); 对于(var j=0;j根据{},缺少,并且使用了单引号。我现在无法测试,但希望它能解决您的问题

  commentThreadsInsert('snippet',
      {},
      {'snippet.channelId': '',
       'snippet.videoId': '',
       'snippet.topLevelComment.snippet.textOriginal': ''
      });
。如果使用应用程序脚本编辑器的“自动完成”,则所需顺序非常明确:

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

因此,解决中解析错误的解决方案是使用所需的方法签名和所需的资源格式:

function startCommentThread(vid, ytch, fc) {
  const resource = {
    snippet: {
      channelId: ytch,
      videoId: vid,
      topLevelComment: {
        snippet: {
          textOriginal: fc
        }
      }
    }
  };
  YouTube.CommentThreads.insert(resource, "snippet");
}

第19行是什么?@noogui刚刚添加了第19行的内容。再次检查问题。我认为这不重要。