· 5 years ago · Jul 12, 2020, 10:14 PM
1from apiclient.discovery import build
2from apiclient.errors import HttpError
3from oauth2client.tools import argparser
4
5
6# Set DEVELOPER_KEY to the API key value from the APIs & auth > Registered apps
7# tab of
8# https://cloud.google.com/console
9# Please ensure that you have enabled the YouTube Data API for your project.
10DEVELOPER_KEY = "abcdefghijklmnopqrstuvwxyz"
11YOUTUBE_API_SERVICE_NAME = "youtube"
12YOUTUBE_API_VERSION = "v3"
13
14def youtube_search(options):
15 youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
16 developerKey=DEVELOPER_KEY)
17
18 # Call the search.list method to retrieve results matching the specified
19 # query term.
20 search_response = youtube.search().list(
21 q=options.q,
22 part="id,snippet",
23 maxResults=options.max_results
24 ).execute()