user3310334
user3310334

Reputation:

Programmatically create YouTube playlist

I have a huge list of YouTube video URLs.

How can I programmatically create playlists on my YouTube account for these videos?

The YouTube API docs: PlaylistItems: insert don't obviously say how to build the request, and don't give examples.

part parameter: The following list contains the part names that you can include in the parameter: contentDetails, id, snippet, status

What's the point of this parameter? What are "the properties that the write operation will set as well as the properties that the API response will include" and how do I use them to create a playlist and add a video to a playlist?

I understand I have to "provide" this in the request body:

{
    "playlistId": string,
    "position?": unsigned integer,
    "resourceId": {
      "kind": string,
      "videoId": string,
    }
  },
  "contentDetails?": {
    "startAt": string,
    "endAt": string,
    "note": string
  }
}

Is that what the body should be? Since status and id are not here why are they options for the part parameter?

What are the exact HTTP requests I must POST to create a playlist and to add a video to a playlist?

Upvotes: 0

Views: 684

Answers (1)

user3310334
user3310334

Reputation:

surprisingly it is (minimum)

{
  part: 'snippet',
  resource: {
    snippet: {
      playlistId,
      resourceId: {
        kind: 'youtube#video',
        videoId
      }
    }
  }
}

The playlistItem goes into a resource key on the top level object.

Since status and id are not here why are they options for the part parameter?

I still don't know

Upvotes: 0

Related Questions