python – 使用forMine设置为false搜索时出现youtube v3 api错误

我正在使用Youtube API版本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时忽略它,而是将其视为字符串参数,当它具有ANY时触发特定条件值). github repo中的客户端代码看起来是正确的,YouTube的发现API也是如此,因此问题很可能是工程师需要解决的后端问题.您可以尝试设置forMine = None以查看是否可以将该参数设置为不发送,或者您可以查看客户端的代码(
https://github.com/google/google-api-python-client/blob/master/googleapiclient/discovery.py)并编写您自己的“构建”功能,该功能将从中获取的forMine参数去掉发现URI.但是,在工程层面解决这个问题之前,必须进行破解性的解决方案;考虑报告:

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

点赞