我正在尝试创建一个使用Google脚本的程序,在某个YouTube频道上传时插入评论。我已经能够从频道获得最新的YouTube视频ID,但是当我尝试插入一个注释时,它会抛出一个错误,"Parse (第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
});
}发布于 2018-06-26 04:05:13
方法的参数。如果使用Apps脚本编辑器的“自动完成”,则非常清楚所需的顺序:

还请注意,您错误地创建了您的资源主体-您有各种子属性。例如,snippet属性是资源的必需成员。三个"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");
}发布于 2018-06-26 03:40:49
根据文档,{}缺失并使用单引号。我现在不能测试这个,但希望它能解决你的问题。
commentThreadsInsert('snippet',
{},
{'snippet.channelId': '',
'snippet.videoId': '',
'snippet.topLevelComment.snippet.textOriginal': ''
});https://stackoverflow.com/questions/51012865
复制相似问题