【问题标题】:How to search youtube video in channel using youtube如何使用 youtube 在频道中搜索 youtube 视频
【发布时间】:2015-07-12 20:41:16
【问题描述】:
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,我获取指定频道中按关键字搜索的 youtube 视频数据,但我想获取指定频道中未按关键字搜索的所有数据

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

【问题讨论】:

    标签: python search youtube youtube-api youtube-data-api


    【解决方案1】:

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

     q=search_keyword,
    

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

    【讨论】:

    • 感谢您的回复,您的回复解决了这个问题,祝您好运!
    猜你喜欢
    • 2016-01-11
    • 1970-01-01
    • 2013-07-02
    • 2019-12-14
    • 2018-09-16
    • 2012-08-02
    • 2014-10-15
    • 2014-11-04
    • 1970-01-01
    相关资源
    最近更新 更多