YouTube API v3: view videos in Python

I need to be able to “love” a specific video by ID through the new YouTube v3 API for an authenticated user. I follow the action / insert guide found here:

https://developers.google.com/youtube/v3/docs/activities/insert

This code sample is great for posting a newsletter on my channel, but when I try to change the body to form a similar statement, I continue to get a 400 error. Here is what Ive changed from the original example in which the dict body is set:

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 configured correctly.

https://developers.google.com/youtube/v3/docs/activities

But I keep getting 400 HttpEror, for example,

<HttpError 400 when requesting https://www.googleapis.com/youtube/v3/activities?alt=json&part=snippet%2CcontentDetails returned "Bad Request">

Ive -, . ? ?

,

Jeff,

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()
+3
1

"" v3, . ( , , "".)

make - playlistItems.insert() (.. POST https://www.googleapis.com/youtube/v3/playlistItems) :

"body": {
  "snippet": {
    "playlistId": LIKED_LIST_ID,
    "resourceId": {
      "kind": "youtube#video",
      "videoId": VIDEO_ID
    }
  }
}

: LIKED_LIST_ID VIDEO_ID. VIDEO_ID, , . LIKED_LIST_ID , channels.list(part = contentDetails).

"contentDetails": {
  "relatedPlaylists": {
    "likes": "LL0c49w3rVoFjTkQVbyRs8Sg",
    "favorites": "FL0c49w3rVoFjTkQVbyRs8Sg",
    "uploads": "UU0c49w3rVoFjTkQVbyRs8Sg",
    "watchHistory": "HL0c49w3rVoFjTkQVbyRs8Sg",
    "watchLater": "WL0c49w3rVoFjTkQVbyRs8Sg"
  }
}

, , . "" .

+3

Source: https://habr.com/ru/post/1788486/


All Articles