ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-07-02 14:55:50  阅读:266  来源: 互联网

标签:python youtube-api youtube-api-v3


我正在使用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

标签:python,youtube-api,youtube-api-v3
来源: https://codeday.me/bug/20190702/1357258.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有