I am trying to create a program using Google Apps Script that inserts a reply to a given youtube comment with its ID. But when I try to insert a comment, it throws an error,
GoogleJsonResponseException: API call to youtube.commentThreads.insert failed with error: Comments cannot be empty. startCommentThread @ Code.gs:42
Line 42: YouTube.CommentThreads.insert(resource, "snippet");
Here's my code:
function startCommentThread(vid,ytch, fc) {
var fc,vid,ytch
fc ="Hi" //This is reply comment
vid ="3a8VpwZm2Kw" //This is video id
ytch ="UCNXOZLBWDbLJxxXcLEpKzVQ" // channel id
const resource = {
snippet: {
channelId: ytch,
videoId: vid,
textOriginal : fc,
parentId : "UgyvUFY31md_zpE9eqV4AaABAg" //comment id
}
}
YouTube.CommentThreads.insert(resource, "snippet");}
CodePudding user response:
The documentation seems to indicate that the structure of your request body is incorrect.
Based on the documentation, I think the request body should look like this:
const resource = {
snippet: {
channelId: ytch,
videoId: vid,
topLevelComment: {
snippet: {
textOriginal: fc
}
}
}
};
EDIT I see now that you want to simply insert a reply to an existing thread. I noticed in your code you were attempting to call YouTube.CommentThreads.insert, so I assumed the goal was to create a new thread.
If you're only looking to reply to an existing thread, and you already know what the ID of that thread is, you can structure your resource like this:
const resource = {
snippet: {
textOriginal: fc,
parentId: threadId // whatever the ID of the parent thread is.
}
};
You'd then call YouTube.Comments.insert, rather than YouTube.CommentThreads.insert.