What paramater am I missing for YouTube Data API Insert method

Viewed 55

I'm using Google's Apps Script for this project. I'm using the YouTube data API V3 and of that API I am using the PlaylistItems class. I'm trying to insert a video into a playlist and I've pieced together what I can from the documentation that they have given.

YouTube.PlaylistItems.insert({
  "part": [
    "snippet"
  ],
  "resource": {
    "snippet": {
      "playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
      "position": 0,
      "resourceId": {
        "kind": "youtube#video",
        "videoId": testVidId
        // testVidId is the ID of the video I'm trying to insert
      }
    }
  }
});

When I run this though, I get an error of

Exception: Invalid number of arguments provided. Expected 2-3 only

My question is: what argument am I missing?

1 Answers

I believe your goal as follows.

  • You want to insert an item to the play list using Google Apps Script.

Modification point:

  • When YouTube.PlaylistItems.insert(resource, part) is used, the arguments are resource, part which are an object and an array of string, respectively.

When your script is modified, it becomes as follows.

Modified script:

YouTube.PlaylistItems.insert(
  {
    "snippet": {
      "playlistId": "PL5t3YGq3D2WnrLyuYL9WCgprQ2RUcwl8a",
      "position": 0,
      "resourceId": {
        "kind": "youtube#video",
        "videoId": testVidId
      }
    }
  },
  ["snippet"]
);

Note:

Reference:

Related