使用频道ID列表,例如:
channel_ids = ['UC6nSFpj9HTCZ5t-N3Ra3-HB','UC6nSFpjSEBUCZ5t-N3Ra3-HB','UC6nrst90rsd3Z5t-N3Ra3-HC','UC6nSFpjd329th0rt-tuTH3-HA']
我想使用YouTube Data API v3检索所有这些频道的50个最新视频上传内容,使用尽可能少的http请求和尽可能少的时间.
我目前的做法是:
from apiclient.discovery import build youtube = build('youtube', 'v3', developerKey=key) channel_ids = ['UC6nSFpj9HTCZ5t-N3Ra3-HB', 'UC6nSFpjSEBUCZ5t-N3Ra3-HB', 'UC6nrst90rsd3Z5t-N3Ra3-HC', 'UC6nSFpjd329th0rt-tuTH3-HA'] videos_by_channel = {} for channel_id in channel_ids: search_response = youtube.search().list(part="id", type='video', order='date', channelId=channel_id, maxResults=50).execute() videoIds = [] for search_result in search_response.get("items", []): if search_result["id"]["kind"] == "youtube#video": videoIds.append(search_result['id']['videoId']) search_response = youtube.videos().list( id=",".join(videoIds), part="id,snippet" ).execute() videos_by_channel[channel_id] = search_response
它工作但使用了很多服务器调用,并不是很快.我已经阅读了文档,但找不到更快的方法,任何想法?