Google youtube API, how do i search for specific k

2019-08-02 11:12发布

问题:

I want to search for keyword related youtube videos, I'm using youtube getdata API.

Reading documentation I came up with this:

http://gdata.youtube.com/feeds/api/videos/-/". urlencode($kwd) ."?orderby=viewCount&max-results=". $max ."&alt=json

But this is not a real search, it gives urls taged with keyword... Youtubes internal search works quite differently I imagine, because comparing results don't match at all.

Any ideas?

回答1:

The URL you offer does a search for any videos in a category where the category includes your keyword. What you want to do instead is to send a query string:

"https://gdata.youtube.com/feeds/api/videos?q=". urlencode($kwd) ."&orderby=viewCount&max-results=". $max ."&alt=json"

This way the feed will match right on the videos rather than the categories.

In the newer v3 of the API, your call would look like:

"https://www.googleapis.com/youtube/v3/search?part=snippet&q=".urlencode($kwd)."&maxResults=".$max."&order=viewCount&key={YOUR_API_KEY}"


回答2:

Use Data API v3, search->list method.

GET https://www.googleapis.com/youtube/v3/search?part=snippet&q=term&key={YOUR_API_KEY}


回答3:

In my opinion, I would use the "q" parameter, for example to search for "dog"

var request = gapi.client.youtube.search.list({ part: 'snippet', q: "dog" });

But I'm just a noob the others guys answers are probably better.