如何使用Google API节点客户端创建YouTube播放列表?

时间:2013-12-30 01:29:30

标签: node.js youtube google-api-nodejs-client

使用Google的google-api-nodejs-client(官方google节点库),我在几个月前运行了这段代码。我把它放在一边。

googleapis.discover('youtube', 'v3').execute(function (err, client) {
    var request = client.youtube.playlists.insert({
         part: 'snippet,status',
         resource: {
             snippet: {
                 title: "hello",
                 description: "description"
             },
             status: {
                 privacyStatus: "private"
             }
          }
     });
    request.withAuthClient(oauth2Client).execute(function (err, res) {...

我已经重新启动了项目并通过npm下载了最新版本的库,现在当我运行上面的代码时,系统地获取以下错误对象:

Object
     code: 400
     errors: Array[1]
         0: Object
             domain: "youtube.playlist"
             message: "Must specify playlist title."
             reason: "playlistTitleRequired"
         length: 1
              length: 1
     message: "Must specify playlist title."

根据文件和样本,这似乎是正确的google sample code

我已经逐步完成了库代码,似乎请求没有正确构建,但在将其报告为可能的错误之前我想问一下蜂巢的想法。

最近有人成功使用图书馆吗?感谢。

2 个答案:

答案 0 :(得分:2)

似乎节点库不遵循api文档中的约定。当使用具有请求参数和主体的api调用时,参数作为调用的第一个参数在对象中传递,并且将主体作为单独的对象作为对象的第二个参数传递。

在我的情况下,请求需要按原样构建:

var request = client.youtube.playlists.insert(
    { part: 'snippet,status'},
    {
      snippet: {
          title: "hello",
          description: "description"
      },
      status: {
          privacyStatus: "private"
      }
    }
);

答案 1 :(得分:0)

对于插入操作,part的值应为snippet和/或status

part: 'snippet,status',

有关详细信息,请查看此documentation