youtube v3 api 将 forMine 设置为 false 进行搜索时出错

youtube v3 api error when searching with forMine set to false

我正在用 Youtube API version 3 编写一些函数。我正在使用 python,但在 google 提供的测试控制台中确认了我的错误。

(我正在发出所有授权请求,只是没有在下面粘贴我的密钥)

Python 客户端库自动将 forMine 参数添加到我的 Search().list() 请求中,但我可以将其设置为 false。我无法从我的请求中删除参数,如果我省略参数,它默认为 true。如果我将它设置为 false,我会得到这个错误:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/youtube/v3/search?forMine=false&maxResults=50&q=week&part=snippet&alt=json&type=playlist&order=date returned "The request contains an invalid combination of search filters and/or restrictions. Note that you must set the <code>type</code> parameter to <code>video</code> if you set a value for the <code>eventType</code>, <code>videoCaption</code>, <code>videoCategoryId</code>, <code>videoDefinition</code>, <code>videoDimension</code>, <code>videoDuration</code>, <code>videoEmbeddable</code>, <code>videoLicense</code>, <code>videoSyndicated</code>, or <code>videoType</code> parameters.">

API Explorer 上的症状:

请求失败(forMine 参数已删除):

GET https://www.googleapis.com/youtube/v3/search?part=snippet&forMine=false&q=week&type=playlist&key={YOUR_API_KEY}

未失败的请求(forMine 参数设置为 false):

GET https://www.googleapis.com/youtube/v3/search?part=snippet&q=week&type=playlist&key={YOUR_API_KEY}

我的 python 失败的代码,我认为应该可以工作: result = youtube_service.search().list(part='snippet', forMine=False, q='test', type='playlist', maxResults=50).execute()

任何人都可以验证这是我的错误还是 API 错误?

看起来 API 中确实存在一个错误,即 forMine 属性在设置为 false 时抛出错误(它应该在 false 时忽略它,而是将其视为字符串参数当它具有任何值时会触发特定条件)。 github 存储库中的客户端代码看起来是正确的,YouTube 的发现 API 也是如此,因此问题很可能是工程师需要解决的后端问题。您可以尝试设置 forMine=None 以查看是否可以让该参数不发送,或者您可以查看客户端代码 (https://github.com/google/google-api-python-client/blob/master/googleapiclient/discovery.py) 并编写您自己的 'build' 函数删除它从发现 URI 中获取的 forMine 参数。但在这个问题在工程层面得到解决之前,有必要使用 hackish 解决方法;考虑报告:

https://code.google.com/p/gdata-issues/issues/list?q=label:API-YouTube