我想从 Live Streaming API 获取最新的聊天消息。但我总是先得到最老的。我可以按相反的顺序得到它吗?我可以设置一个属性来实现这一点吗?
这是一些示例代码:
if ($_GET['action'] == "listchatmessages")
{
$htmlBody .= '<h1>Chatnachrichten</h1>';
$broadcastsChatResponse = $youtube->liveChatMessages ->listLiveChatMessages (
$broadcastItem['snippet']['liveChatId'], 'snippet');
$myfile = fopen("chatmessages.txt", "w") or die("Unable to open file!");
$count = 0;
if ($_GET['search'] != "")
{
if (!empty($broadcastsChatResponse['items']))
{
foreach ($broadcastsChatResponse['items'] as $broadcastChatItem)
{
if ($count < 200)
{
$broadcastsDetailsChatResponse = $youtube->liveChatMessages ->listLiveChatMessages (
$broadcastChatItem['snippet']['liveChatId'], 'authorDetails');
$broadcastDetailsChatItem = $broadcastsDetailsChatResponse['items'][0];
if ((preg_match('/'.$_GET['search'].'/',$broadcastChatItem['snippet']['textMessageDetails']['messageText'])) OR $_GET['search'] == 'all')
{
$message = $broadcastChatItem['snippet']['authorChannelId'].'_'.$broadcastDetailsChatItem['authorDetails']['displayName'].'_'.$broadcastChatItem['snippet']['textMessageDetails']['messageText']."\n";
$htmlBody .= '<li> Author: <a href="'.$broadcastChatItem['snippet']['authorChannelId'].'">'.$broadcastDetailsChatItem['authorDetails']['displayName'].'</a> schrieb: '.$broadcastChatItem['snippet']['textMessageDetails']['messageText'].'</li>';
$count++;
fwrite($myfile, $message);
}
}
else
{
break;
}
}
$htmlBody .= '<h4> Alle Chatnachrichten empfangen (Anzahl der teilnehmenden Nahcrichten: '.$count.')</h4>';
}
else
{
$htmlBody .= '<p>Der Stream scheint nicht online zu sein</p>';
}
}
else
{
$htmlBody .= 'Kein Suchwort. Nutze all um alle Nachrichten zu nehmen';
}
fclose($myfile);
}