按标题搜索顺序 youtube api

search order by title youtube api

如何在 youtube api 的 php 中按标题排序?在 search.list 的文档中,它说 order 是一个可选参数。如何按标题或日期订购打印的内容? 试试{

// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
  'q' => $_GET['q'],
  'maxResults' => $_GET['maxResults'],
));

$videos = '';
$channels = '';
$playlists = '';
// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach ($searchResponse['items'] as $searchResult) {
  switch ($searchResult['id']['snippet']) {
    case 'youtube#video':
      $videos .= sprintf('<li>title=%s link = http://youtube.com/watch?v=%s/ channelid = %s</li><br> ',
          $searchResult['snippet']['title'], $searchResult['id']['videoId'], $searchResult['snippet']['channelTitle']);
      break;

您可以使用 order 参数按标题、日期、评分、相关性、videoCount 和 viewCount 进行排序。查看订单文档:https://developers.google.com/youtube/v3/docs/search/list

此代码按标题排序

// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
  'q' => $_GET['q'],
  'maxResults' => $_GET['maxResults'],
  'order' => 'title'
));

此代码按日期排序

// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
  'q' => $_GET['q'],
  'maxResults' => $_GET['maxResults'],
  'order' => 'date'
));