def get_youtube_vid_id(self, query, max_results=10):
"""
Makes a request to youtube API with a search query and returns the
corresponding video's id.
:param query: search query of type string to be used for
searching youtube.
:param max_results: The maximum results returned by searching youtube
:returns: The movie id of the first video came up in the youtube search
"""
youtube = build(Connection.YOUTUBE_API_SERVICE_NAME,
Connection.YOUTUBE_API_VERSION,
developerKey=self.keys['google'])
search_response = youtube.search().list(
q=query,
part="id,snippet",
maxResults=max_results
).execute()
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
return search_result["id"]["videoId"]
else:
return None
评论列表
文章目录