未记录的函数 - gapi.client.youtube.commentThreads.insert

Undocumented function - gapi.client.youtube.commentThreads.insert


当我浏览 Google YouTube DATA API 并找到对象 gapi.client.youtube.commentThreads.insert 时,我尝试使用它但我不知道如何使用它并且 Data API 文档没有不多说了,insted of this Google uses buildApiRequest function to create request
我试着像上面这样写 运行 代码,但是 returns 错误 400

代码:

    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();

回应

{
 "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"
 }
}

我找到了解决方案,我当时很愚蠢,因为参数必须通过对象传递 - 这是一个使用此函数的人的示例。

var c = new gapi.client.youtube.commentThreads.insert(
    {
        "part": "snippet"
    },
    {
      "snippet": {
        "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
        "videoId": "NeF0zpT4gNE",
        "topLevelComment": {
          "snippet": {
            "textOriginal": "Hello from API"
          }
        }
      }
    }   
);
c.execute();