2

我正在尝试使用 YouTube Data API v3 进行 YouTube 主题搜索。我发现有许多看似流行的 Freebase 主题,即使 safeSearch 参数设置为“none”,YouTube 也没有返回任何结果。例如,当我尝试在 YouTube 上搜索主题“酒精饮料”(/m/012mj) 时,API 会引发异常。

from apiclient.discovery import build
from apiclient.errors import HttpError

DEVELOPER_KEY = "blah blah"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"

youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
  developerKey=DEVELOPER_KEY)
topic_id = "/m/012mj"
try:
  search_response = youtube.search().list(
    topicId=topic_id,
    type="video",
    part="id",
    safeSearch="none",
    q="",
  ).execute()
except HttpError,e:
  print e

<HttpError 400 when requesting https://www.googleapis.com/youtube/v3/search?topicId=%2Fm%2F012mj&q=&safeSearch=none&part=id&key=AIzaSyC7MDamoleicn233r8mTyK2sohcV4A3Aq8&alt=&type=video returned "Invalid combination of search filters and/or restrictions.">

有什么建议么?

更新

这不再返回 400 错误。API 现在返回没有项目的搜索响应。至少这有助于我区分错误和没有结果的搜索响应。但是,即使将 safeSearch 设置为“无”,YouTube 也不会返回该主题的搜索结果,这似乎仍然很奇怪。

4

1 回答 1

1

Have you considered setting the max-results parameter? I have no experience with the YouTube flavor of the Freebase api, but have read that they recommend limiting the results for videos to 10 rather than accepting the default of 25. Otherwise it is odd that they would send a 400 (bad request) rather than a 401 or so.

于 2013-06-28T23:41:48.403 回答