0

Using Google's google-api-nodejs-client (official google node library), I had this piece of code running many months ago. I had left it aside.

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) {...

I have restarted the project and downloaded the latest version of the library through npm and now when I run the code above I systematically get the following error object:

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."

Which according to the document and sample seems correct google sample code

I've stepped through the library code, it seems that the request is not being built properly but before reporting it as a possible bug I wanted to ask the hive mind.

Anyone had success using the library recently? Thanks.

machunter
  • 967
  • 1
  • 11
  • 27

2 Answers2

2

It seems that the node library doesn't follow the convention in the api documentation. when calling an api with has request parameters and a body, the parameters are passed in an object as the first parameters of the call, and the body as a separate object as the second parameter of the object.

In my case the request needs to be built as such:

var request = client.youtube.playlists.insert(
    { part: 'snippet,status'},
    {
      snippet: {
          title: "hello",
          description: "description"
      },
      status: {
          privacyStatus: "private"
      }
    }
);
machunter
  • 967
  • 1
  • 11
  • 27
0

For insert operation the value of part should be snippet and/or status

part: 'snippet,status',

For more details check this documentation.

vinayr
  • 11,026
  • 3
  • 46
  • 42