2017-06-04 106 views
0

如何在youtube api中通過php中的標題進行排序?在search.list的文檔中,它表示訂單是一個可選參數。如何按照標題或日期排列我打印的內容? 嘗試{按標題搜索的順序youtube api

// 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; 

回答

1

可以使用命令參數的名稱,日期,等級,相關性,VIDEOCOUNT和收視次數進行排序。看看在文檔順序: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' 
)); 
+0

感謝!我得到它的工作 –

+0

太棒了!我很高興聽到這個消息。 –

+0

每當我做'訂單'=>'viewCount'它不會返回任何東西 –