gpt4 book ai didi

python - 如何使用 youtube 在 channel 中搜索 youtube 视频

转载 作者:行者123 更新时间:2023-12-03 06:23:51 25 4
gpt4 key购买 nike

def get_videos(search_keyword):
youtube = build(YOUTUBE_API_SERVICE_NAME,
YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
try:
search_response = youtube.search().list(
q=search_keyword,
part="id,snippet",
channelId=os.environ.get("CHANNELID", None),
maxResults=10, #max = 50, default = 5, min = 0
).execute()
videos = []
channels = []
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
title = search_result["snippet"]["title"]
videoId = search_result["id"]["videoId"]
channelTitle = search_result["snippet"]["channelTitle"]
cam_thumbnails = search_result["snippet"]["thumbnails"]["medium"]["url"]
publishedAt = search_result["snippet"]["publishedAt"]
channelId = search_result["snippet"]["channelId"]
data = {'title' : title,
'videoId' : videoId,
'channelTitle' : channelTitle,
'cam_thumbnails' : cam_thumbnails,
'publishedAt' : publishedAt}
videos.append(data)
elif search_result["id"]["kind"] == "youtube#channel":
channels.append("%s (%s)" % (search_result["snippet"]["title"],
search_result["id"]["channelId"]))


except Exception as e:
print e

现在,我正在使用 python youtube data api,我得到了在指定 channel 中按关键字搜索的 youtube 视频数据,但我想获取在指定 channel 中没有按关键字搜索的所有数据

如何获取指定 channel 中的 youtube 视频数据?我要获取的数据必须是指定 channel 中的所有数据

最佳答案

我不是 100% 确定我知道您在问什么,但我想您是在问如何获取 channel 中的所有视频,而不仅仅是与您的关键字相关的视频?如果这是正确的,您应该能够删除:

 q=search_keyword,

根据您的请求,API 应返回 channel 中的所有视频。如果您要问其他问题,请在您的问题中澄清。

关于python - 如何使用 youtube 在 channel 中搜索 youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30013582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com