Google youtube API, how do i search for specific keyword?

本小妞迷上赌 提交于 2019-12-23 23:55:19

问题


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.



来源:https://stackoverflow.com/questions/20125750/google-youtube-api-how-do-i-search-for-specific-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!