问题
When I was browsing Google YouTube DATA API and I found object gapi.client.youtube.commentThreads.insert, I tried to use it but I didn't know how to use it and Data API documentation doesn't tell much about it, insted of this Google uses buildApiRequest function to create request.
I tried to write and run code like this above, but it returns error 400
Code:
var c = new gapi.client.youtube.commentThreads.insert(
{
"part":"snippet"
},{
'snippet.channelId': 'UC_x5XG1OV2P6uZZ5FSM9Ttw',
'snippet.videoId':'NeF0zpT4gNE',
'snippet.topLevelComment.snippet.textOriginal':'Hello from API'
});
c.execute();
Response
{
"error": {
"errors": [
{
"domain": "youtube.commentThread",
"reason": "channelOrVideoIdMissing",
"message": "Each comment thread must be linked to a channel or video.\u003cul\u003e\u003cli\u003eIf the comment applies to a channel, make sure that the resource specified in the request body provides a value for the \u003ccode\u003e\u003ca href=\"/youtube/v3/docs/commentThreads#snippet.channelId\"\u003esnippet.channelId\u003c/a\u003e\u003c/code\u003e property. A comment that applies to a channel appears on the channels \u003cb\u003eDiscussion\u003c/b\u003e tab.\u003c/li\u003e\u003cli\u003eIf the comment applies to a video, make sure the resource specifies values for both the \u003ccode\u003e\u003ca href=\"/youtube/v3/docs/commentThreads#snippet.channelId\"\u003esnippet.channelId\u003c/a\u003e\u003c/code\u003e and \u003ccode\u003e\u003ca href=\"/youtube/v3/docs/commentThreads#snippet.videoId\"\u003esnippet.videoId\u003c/a\u003e\u003c/code\u003e properties. A comment that applies to a video appears on the videos watch page.\u003c/li\u003e\u003c/ul\u003e",
"locationType": "other",
"location": "body.snippet"
}
],
"code": 400,
"message": "Each comment thread must be linked to a channel or video.\u003cul\u003e\u003cli\u003eIf the comment applies to a channel, make sure that the resource specified in the request body provides a value for the \u003ccode\u003e\u003ca href=\"/youtube/v3/docs/commentThreads#snippet.channelId\"\u003esnippet.channelId\u003c/a\u003e\u003c/code\u003e property. A comment that applies to a channel appears on the channels \u003cb\u003eDiscussion\u003c/b\u003e tab.\u003c/li\u003e\u003cli\u003eIf the comment applies to a video, make sure the resource specifies values for both the \u003ccode\u003e\u003ca href=\"/youtube/v3/docs/commentThreads#snippet.channelId\"\u003esnippet.channelId\u003c/a\u003e\u003c/code\u003e and \u003ccode\u003e\u003ca href=\"/youtube/v3/docs/commentThreads#snippet.videoId\"\u003esnippet.videoId\u003c/a\u003e\u003c/code\u003e properties. A comment that applies to a video appears on the videos watch page.\u003c/li\u003e\u003c/ul\u003e"
}
}
回答1:
I found solution, I was stupid because parameters must be passed by object - here is example for someone who would use this function.
var c = new gapi.client.youtube.commentThreads.insert(
{
"part": "snippet"
},
{
"snippet": {
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"videoId": "NeF0zpT4gNE",
"topLevelComment": {
"snippet": {
"textOriginal": "Hello from API"
}
}
}
}
);
c.execute();
来源:https://stackoverflow.com/questions/50533800/undocumented-function-gapi-client-youtube-commentthreads-insert