How to get a list of the entire video (or the maximum amount that an api allows) by the channel name?

Direct in the right direction and correct if I'm wrong.

As I understand, I first need to get an api-key for my project https://console.developers.google.com With this key in mind, I have to go to the youtube api and get a json-object that needs to be parsed to the elements I need. An example of an appeal to api is already in one of the questions , but for another version of api, I will be grateful if someone specifies how to build a request and get an adequate answer, I will be grateful.

    2 answers 2

    The API you need to use is Youtube Data API, its current version is V3. In this question, the correct answer recommends the correct sequence of actions. Duplicate in Russian.

    1. Get channel id. The easiest way to do this is to go to the channel page and pull the id out of the link. For example, for the Moscow Python channel id would be UC-OVMPlMA3-YCIeg4z5z23A .

    2. Get a playlist id. To do this, you need to make a request to the channels.list , specifying the channel id from the first item as id The response has a contentDetails structure, the uploads key in it, the playlist id in it.

    3. Get a video in the playlist. For this you need to make a request to playlistitems.list , specifying playlistid (from the second paragraph) and part=snippet . The answer will be a list of different video options. For example, a picture, a title, a description, and an id of a video that you can get a link from. Victory.

    For experiments, I recommend using the Youtube API Explorer - you can quickly understand the sequence of method calls and their results.

    When this is clear, it will remain to transfer the code to Python. For requests I recommend using the Requests library. The official SDK is best not to use without much need - it is very wordy, complex and inconvenient.

    • thanks for the answer! I myself have already come to this, although I did not write right away, below is my decision, suddenly it will be useful to someone - while1pass
    • For thanks, there is a "Accept" button. :) - Lebedev Ilya

    Above Lebedev, Ilya has already indicated a sequence of actions for solving. Below I present my result.

    To begin with, we go to the YouTube Data API Overview , where the entire sequence of actions is described, in brief: we start a Google account if you don’t have one, go to the developer console, create a project, link youtube-api, get your api-key (in the code indicated as YOUR_API_KEY).

    A query to api will allow you to get only 50 results (api restriction). In my case, I can get the 50 most recently downloaded video feeds. Or you can get 50 videos from each playlist, then you need to use the scheme from the answer above.

    uri appeal to api next:

     https://www.googleapis.com/youtube/v3/search?key={YOUR_API_KEY}&channelId={CHANNEL_ID}&part=snippet,id&order=date&maxResults=50 

    Below is the code that takes the response id, title, preview and description of all videos and frauds sheet.

     # coding=utf-8 from __future__ import unicode_literals import requests import json def game_video_list(game): """ Get channel's upload videos| 50 limit""" youtube_link = {ссылка на канал вводится пользователем} # отрезаем id канала CHANNEL_ID = game.channel.rsplit('/', 1)[-1] try: YOUTUBE_URI = 'https://www.googleapis.com/youtube/v3/search?key={}&channelId={}&part=snippet,id&order=date&maxResults=50' FORMAT_YOUTUBE_URI = YOUTUBE_URI.format( YOUTUBE_API_KEY, CHANNEL_ID) content = requests.get(FORMAT_YOUTUBE_URI).text data = json.loads(content) video_list =[] keys = 'id', 'title', 'description', 'preview' for item in data.get('items'): id = item.get('id').get('videoId') title = item.get('snippet').get('title') description = item.get('snippet').get('description') preview = item.get('snippet').get('thumbnails').get('high').get('url') values = id, title, description, preview if id: video_item =dict(zip(keys, values)) video_list.append(video_item) return video_list except: return {}