【问题标题】:search order by title youtube api按标题 youtube api 搜索顺序
【发布时间】:2017-06-04 13:52:16
【问题描述】:

如何在 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;

【问题讨论】:

    标签: php youtube youtube-api youtube-data-api


    【解决方案1】:

    您可以使用 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'
    ));
    

    【讨论】:

    • 太棒了!我很高兴听到这个消息。
    • 每当我做 'order' => 'viewCount' 它什么都不返回
    • viewCount 仅适用于频道。它将频道从上传最多的视频排序到最少上传的视频。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-18
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 2014-03-16
    相关资源
    最近更新 更多