garrettlynchirl
garrettlynchirl

Reputation: 910

YouTube listsearch filter

Simple question, I'm using the google-api-php-client to search youtube for videos and I want to filter the results to only return videos. The library says you can do this:

By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource. (search.list)

But I'm unclear as to how. How should I be modifying the query?

$searchResponse = $youtube->search->listSearch('id,snippet', array(
      'q' => $_GET['q'],
      'maxResults' => $_GET['maxResults'],
    ));

thanks in advance.

Upvotes: 2

Views: 647

Answers (1)

theduck
theduck

Reputation: 2617

You can specify the type as video, for instance:

$searchResponse = $youtube->search->listSearch('id,snippet', array(
  'q' => $_GET['q'],
  'maxResults' => $_GET['maxResults'],
  'type' => 'video'
));

By default, the type field is video, channel, playlist so you will get all 3 by default.

Upvotes: 3

Related Questions