Search code examples
phpsearchyoutube-apifeed

YouTube API Search for Exact Phrase


I am using YouTube PHP API to retrieve a feed that searches for the exact term "super bowl commercials".

However, I sometimes get irrelevant videos in the feed.

$searchTerms stores the search query.

$searchTerms2 = str_replace(" ","+",$searchTerms);
$searchTerms2 = '"' . $searchTerms2 . '"';

$query->setVideoQuery($searchTerms2);

Does any one know of a solution to this issue?


Solution

  • From reference: To search for an exact phrase, enclose the phrase in quotation marks. For example, to search for videos matching the phrase "spy plane", set the q parameter to %22spy+plane%22.

    So you urlencode your quotation marks?