Search multiple keywords in Youtube GData Youtube class

1.7k views Asked by At

The Youtube API document says that multiple keywords can be searched during video fetch as per the below link.

https://developers.google.com/youtube/2.0/reference#Searching_for_videos

The below link gives some examples for the same. The example provided for the "q" parameter says that we can use NOT (-) and OR (|) operator in the search:

https://developers.google.com/youtube/2.0/reference#qsp

Example: q=boating%7Csailing does a search for either boating or sailing.

I am able to understand these points. My question is I am using ZendGData library in Zend Framework 2 to search the videos. I am not sure how to provide multiple keywords for the search.

$yt = new ZendGData\YouTube();
$query = $yt->newVideoQuery();

All the combinations that I tried is provided below. None of them works.

$query->setQuery("french,tamil");
$query->setQuery("french|tamil");
$query->setQuery("french%7Ctamil");
$query->setQuery("french or tamil");

Note: The docs says to use url encode so that the pipe symbol is encoded. That's why I treid %7C in the search.

The URL generated by the ZendGData class is: https://gdata.youtube.com/feeds/api/videos?q=french|tamil&start-index=58&max-results=50&safeSearch=none&orderby=viewCount&format=5&v=2

This does not fetch the videos with keyword "tamil". All the videos are from the first keyword only.

Please point me in the correct direction.

1

There are 1 answers

4
ceasar On

Or this with a simple space. Tested it and it found all the keywords https://gdata.youtube.com/feeds/api/videos?q=french%20tamil&start-index=1&max-results=50&safeSearch=none&orderby=viewCount&format=5&v=2

So try this $query->setQuery("french tamil"); or $query->setQuery(urlencode(("french tamil"));

Also your start-index looks strange and should that not be start-index=1