首页 > 解决方案 > 在 YouTube 上获取热门新闻视频的 ID 时遇到问题?

问题描述

我一直在尝试使用 YouTube 数据 API 从美国获取热门新闻视频。但是,虽然我没有收到错误,但我没有收到任何结果。我很难相信没有结果,因为 YouTube 的热门新闻页面显示了许多视频。

我得到的回报:

{'kind': 'youtube#videoListResponse', 'etag': 'KtFSnIG_fmDzS9uX1a7JuXFZJbk', 'items': [], 'pageInfo': {'totalResults': 0, 'resultsPerPage': 5}}

我的代码:

youtube = build("youtube","v3", developerKey=apiKey)

  
request = youtube.videos().list(
    part = "id",
    chart = "mostPopular",
    regionCode = "US",
    videoCategoryId = "25"
)

response = request.execute()

print(response)

标签: youtube-apiyoutube-data-apigoogle-api-python-client

解决方案


试试这个,看看你是怎么做的。

result = self.youtube.search().list(
        part="snippet",
        regionCode="US",
        videoCategoryId = 25,
        order="viewCount",
        type="video",
    ).execute()

    for item in result['items']:
        print()
        print(item["id"]["videoId"])
    return result

一切顺利。


推荐阅读