1
votes

When I attempt to add a video to a playlist I get an error

{ "error": { "errors": [ { "domain": "youtube.playlistItem", "reason": "resourceIdRequired", "message": "Required" } ], "code": 400, "message": "Required" } }

My code is as such

<cfset jsonPlaylist={
  "snippet"= 
  {
    "playlistId"= "#form.ytPlaylist#",
    "resourceId"= 
    {
      "kind"= "youtube##video",
      "videoId"= "#YouTubeID#"
    }
  }
}>

<cfhttp result="assignplaylist" method="POST" url="https://www.googleapis.com/youtube/v3/playlistItems?part=snippet">
    <cfhttpparam type="header" value="Bearer #session.youTubeAuth.access_token#" name="Authorization">
    <cfhttpparam type="body" value="#serializeJSON(jsonPlaylist)#">
</cfhttp>

If I dump jsonPlaylist I get

{"snippet":{"resourceId":{"kind":"youtube#video","videoId":"xxxxxxxxx"},"playlistId":"xxxxxxxxxx"}}

If I paste this into the API Explorer here https://developers.google.com/youtube/v3/docs/playlistItems/insert#try-it

It works correctly.

Any suggestions? Thanks

1

1 Answers

3
votes

I was missing the following line in my http request.

<cfhttpparam type="header" value="application/json; charset=UTF-8" name="Content-Type">