如何通过ID
使用Youtube API v3
.
到目前为止,我只遇到过搜索机制和其他但不是专门用于获取单个视频的机制,我目前拥有的代码是:
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)
但我意识到这种方法效率不高,反而浪费时间和资源。我该怎么办?
YouTube API 搜索调用用于搜索。您要使用视频调用并传入要查询的视频 ID。
例子:
https://www.googleapis.com/youtube/v3/videos?part=snippet&id=xE_rMj35BIM&key=YOUR_KEY
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句