0

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.

Purus
  • 5,701
  • 9
  • 50
  • 89
  • The probelm is only with word Tamil? have you passed checked tamil as a parameter (single parameter) – noobie-php Sep 30 '13 at 19:32
  • No.. Not just with the word "tamil".. if I change the order of words to "tamil%7Cfrench", I get only Tamil related videos. – Purus Sep 30 '13 at 19:33
  • If only one keyword is given, it works fine. – Purus Sep 30 '13 at 19:38
  • 1
    try this as parameter %22french+tamil%22 this is for ZF1 but i think it will still work here, this 1 refers to "french tamil". In short idea is to use (+) to escape URl. – noobie-php Sep 30 '13 at 19:44
  • This does not have any results.. test link is https://gdata.youtube.com/feeds/api/videos?q=%22tamil+french+spanish%22&start-index=36&max-results=20&safeSearch=none&orderby=viewCount&format=5&v=2 – Purus Oct 01 '13 at 06:57

1 Answers1

0

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

ceasar
  • 1,512
  • 3
  • 17
  • 25
  • Thanks for that. I will try on that. Regarding start-index, it can be any value which represents the page number to start with. I am looking for random videos and so I am using some random number every time in my code. – Purus Oct 01 '13 at 05:48
  • It gives no output feed.. test URL : https://gdata.youtube.com/feeds/api/videos?q=tamil+french+spanish&start-index=36&max-results=20&safeSearch=none&orderby=viewCount&format=5&v=2 – Purus Oct 01 '13 at 06:58
  • That's because you are using a + instead of a space and futhermore your start index start at 36 but there are only 3 results https://gdata.youtube.com/feeds/api/videos?q=tamil%20french%20spanish&start-index=1&max-results=20&safeSearch=none&orderby=viewCount&format=5&v=2 – ceasar Oct 01 '13 at 18:00
  • + is because space iss urlencoded as plus. Yeah, I just noticed your point. But its strange that it gets only 3 results as my requirement is to search out for all those 3 keywords. I am sure its not the actual one.. – Purus Oct 01 '13 at 18:06