问题
I am writing some functions with the Youtube API version 3
. I am using python
but confirmed my error in the google provided test console.
(I am making all authorized requests, just didn't paste my key below)
The Python client library automatically adds the forMine
parameter to my Search().list()
request, though I can set it to false. I am unable to remove the parameter from my request, if I omit the argument, it defaults to true. If I set it to false, I get this error:
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.">
Symptoms on the API Explorer:
request that fails (forMine
parameter removed):
GET https://www.googleapis.com/youtube/v3/search?part=snippet&forMine=false&q=week&type=playlist&key={YOUR_API_KEY}
request that doesn't fail (forMine
parameter set to false):
GET https://www.googleapis.com/youtube/v3/search?part=snippet&q=week&type=playlist&key={YOUR_API_KEY}
my python code that fails which I believe should work:
result = youtube_service.search().list(part='snippet', forMine=False, q='test', type='playlist', maxResults=50).execute()
Can anyone verify that this is either my bug or an API bug?
回答1:
It does look like there is a bug in the API whereby the forMine attribute is throwing an error when set to false (it should be ignoring it when false, but instead it's treating it like a string parameter where it triggers particular conditions when it has ANY value). The client code in the github repo looks correct, as does the discovery API for YouTube, so the problem is most likely a backend one that the engineers need to address. You could try setting forMine=None to see if you can get that parameter to not send, or you could look at the code for the client (https://github.com/google/google-api-python-client/blob/master/googleapiclient/discovery.py) and write your own 'build' function that strips out the forMine parameter it gets from the discovery URI. But until this issue is addressed at the engineering level then hackish workarounds will be necessary; consider reporting at:
https://code.google.com/p/gdata-issues/issues/list?q=label:API-YouTube
来源:https://stackoverflow.com/questions/33508077/youtube-v3-api-error-when-searching-with-formine-set-to-false