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:
https://developers.google.com/youtube/v3/docs/activities/insert
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:
body = {}
body["snippet"] = dict(type='like')
body["contentDetails"] = dict(
like=dict(
resourceId=dict(
kind="youtube#video",
videoId='_M9khs87xQ8'
)
)
)
According to the following documentation, the fields seem to be setup correctly.
https://developers.google.com/youtube/v3/docs/activities
But I keep getting a 400 HttpEror like so
<HttpError 400 when requesting https://www.googleapis.com/youtube/v3/activities?alt=json&part=snippet%2CcontentDetails returned "Bad Request">
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?
Thanks in advance, Justin
Update
This issue has been answered by Jeff and the working solution is posted below
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()