如何在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;
答案 0 :(得分: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'
));