Youtube v3 Api按ID获取视频

问题描述 投票:0回答:1

如何通过q​​azxswpoi使用ID获取单个视频。

到目前为止,我只遇到了搜索机制和其他,但不是特别是一个获得单个视频,我目前的代码是:

Youtube API v3

但我意识到这种方法效率不高,而是浪费时间和资源。我该怎么办呢?

python-3.x youtube-api google-client
1个回答
1
投票

YouTube API搜索调用适用于搜索。您想使用def youtube_search(q, max_results=1,order="relevance", token=None, location=None, location_radius=None): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) search_response = youtube.search().list( q=q, type="video", pageToken=token, order = order, part="id,snippet", maxResults=max_results, location=location, locationRadius=location_radius ).execute() videos = [] for search_result in search_response.get("items", []): if search_result["id"]["kind"] == "youtube#video": videos.append(search_result) try: nexttok = search_response["nextPageToken"] return(nexttok, videos) except Exception as e: nexttok = "last_page" return(nexttok, videos) 并传入您要查询的视频ID。

例:

videos call
© www.soinside.com 2019 - 2024. All rights reserved.