title: YouTube API v3: Liking a video in Python
body: <p>I need to be able to "like" a specific video by ID through the new YouTube API v3 for an authenticated user. I am following the activities/insert guide found here:</p>
  
  <p><a href="https://developers.google.com/youtube/v3/docs/activities/insert" rel="nofollow">https://developers.google.com/youtube/v3/docs/activities/insert</a></p>
  
  <p>This example code runs fine for posting a bulletin to my channel but when I try to modify the body to form a like statement, I keep getting a 400 error. Here is what Ive changed from the original example where the body dict is setup:</p>
  
  <pre><code>body = {}
  body["snippet"] = dict(type='like')
  body["contentDetails"] = dict(
      like=dict(
          resourceId=dict(
              kind="youtube#video",
              videoId='_M9khs87xQ8'
          )
      )
  )
  </code></pre>
  
  <p>According to the following documentation, the fields seem to be setup correctly.</p>
  
  <p><a href="https://developers.google.com/youtube/v3/docs/activities" rel="nofollow">https://developers.google.com/youtube/v3/docs/activities</a></p>
  
  <p>But I keep getting a 400 HttpEror like so</p>
  
  <pre><code>&lt;HttpError 400 when requesting https://www.googleapis.com/youtube/v3/activities?alt=json&amp;part=snippet%2CcontentDetails returned "Bad Request"&gt;
  </code></pre>
  
  <p>Ive also tried adapting this to favorite a video action but get the same result. Am I missing some of the required fields? Is this the correct endpoint for creating a like action?</p>
  
  <p>Thanks in advance,
  Justin</p>
  
  <h1><strong>Update</strong></h1>
  
  <p>This issue has been answered by Jeff and the working solution is posted below</p>
  
  <pre><code>for item in youtube.channels().list(part='contentDetails', mine=True).execute().get('items', []):
      playlists = item['contentDetails'].get('relatedPlaylists', {})
      if 'likes' in playlists:
          body = {
              "snippet": {
                  "playlistId": playlists['likes'],
                  "resourceId": {
                      "kind": 'youtube#video',
                      "videoId": '_M9khs87xQ8'
                  }
              }
          }
          youtube.playlistItems().insert(body=body, part='snippet').execute()
  </code></pre>