我正在尝试使用 Google Apps 脚本创建一个程序,该程序会在某个 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
});
}
Per Apps Script advanced services documentation, when specifying resources (such as a CommentThread) they are the first parameter to a method. If you use the Apps Script editor's autocomplete, it is very clear about the required order:
另请注意,您错误地创建了资源主体 - 您有各种子属性。例如,snippet
财产是必需的成员CommentThread资源. Three "snippet.___"
属性不等于一个snippet
具有 3 个子属性的属性。
因此解决解析错误的解决方案YouTube.CommentThreads.insert是使用所需的方法签名,以及所需的资源格式:
function startCommentThread(vid, ytch, fc) {
const resource = {
snippet: {
channelId: ytch,
videoId: vid,
topLevelComment: {
snippet: {
textOriginal: fc
}
}
}
};
YouTube.CommentThreads.insert(resource, "snippet");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)