使用Google Apps脚本插入YouTube顶层评论 [英] Insert YouTube top level comment using Google Apps Script
本文介绍了使用Google Apps脚本插入YouTube顶层评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Google Apps脚本创建一个程序,该脚本在某个YouTube频道上传时插入评论。我已经能够从该频道获得最新的YouTube视频ID,但当我尝试插入评论时,它抛出一个错误,"Parse Error(第19行,文件‘Code’)"。
第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
});
}
推荐答案
Per Apps Script advanced services documentation, when specifying resources (such as a CommentThread
) they are the first parameter to a method。如果您使用Apps脚本编辑器的自动完成功能,则所需顺序非常清楚:
snippet
属性是CommentThread
resource的必需成员。三个"snippet.___"
属性不等于一个具有3个子属性的snippet
属性。
因此,解决YouTube.CommentThreads.insert
中的解析错误的解决方案是使用所需的方法签名,以及所需的资源格式:
function startCommentThread(vid, ytch, fc) {
const resource = {
snippet: {
channelId: ytch,
videoId: vid,
topLevelComment: {
snippet: {
textOriginal: fc
}
}
}
};
YouTube.CommentThreads.insert(resource, "snippet");
}
这篇关于使用Google Apps脚本插入YouTube顶层评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文