Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube API error v3 - 'No Filter Selected'

I'm using the Youtube V3 Api and here's the code snippet to pull the top ten videos from my youtube channel. (This same query works perfectly in the google API explorer @ https://developers.google.com/apis-explorer/)

url_start = "https://www.googleapis.com/youtube/v3/videos?" + \ 
            "order=viewCount&part=snippet&forMine=true" + \
            "&type=video&maxResults=10&key=MY_API_KEY"
data = requests.get(url_start).json()

But I get this error:

{u'error': {u'code': 400,
            u'message': u'No filter selected.',
            u'errors':[{u'locationType': u'parameter',
                        u'domain': u'youtube.parameter',
                        u'message': u'No filter selected.',
                        u'reason': u'missingRequiredParameter',
                        u'location': u''}]}}

I know the key is valid because if I can do the same query without forMine

https://www.googleapis.com/youtube/v3/search?part=snippet&key=MY_API_KEY

And I get the top videos overall from youtube. Is there a better way to do this or a workaround?

like image 724
Fight Fire With Fire Avatar asked May 21 '15 13:05

Fight Fire With Fire


1 Answers

The forMine parameter only works for an authenticated user (one who has gone through the oAuth2 flow with your app), so the missing parameter that your request is complaining about is the needed access token.

If your goal is to have a private script running that shows you your top ten videos at any given time, then you can set up a temporary routine in your app that will allow you to manually authenticate with oAuth2 and capture the refresh token; if you store that, then on future requests the refresh token can get an access token without you having to authorize by hand.

If your goal is to create a dashboard so that your users can see their own top ten videos, then you'll just have to wire in oAuth2 authentication into your flow, and send in the access token with every request. The gapi client for Python makes this pretty simple.

If you want to do it without the forMine parameter of the videos list, you can go back to the search endpoint and pass in the user channel ID (this requires knowing it in advance, of course, whereas the authenticated method will work for any user that logs in without you having to know who they are):

https://www.googleapis.com/youtube/v3/search?order=viewCount&part=snippet&channelId={channel id here}&maxResults=25&key={YOUR_API_KEY}
like image 180
jlmcdonald Avatar answered Sep 20 '22 01:09

jlmcdonald