gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:26:06 25 4
gpt4 key购买 nike

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

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

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 代码应该可以工作:
结果 = youtube_service.search().list(part='snippet', forMine=False, q='test', type='playlist', maxResults=50).execute()

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

最佳答案

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

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

关于python - 将 forMine 设置为 false 进行搜索时出现 youtube v3 api 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33508077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com