我使用alaouy /的Youtube包在我laravel 5.4公司获取我的所有视频的从我的频道与该代码如何获取最新的YouTube视频在Laravel
$videoList = Youtube::listChannelVideos('UC9PWIZ20pnEXgT1fT69bX8A', 50);
但它显示我老首先我要到获取最新的第一我该怎么办 谢谢
我使用alaouy /的Youtube包在我laravel 5.4公司获取我的所有视频的从我的频道与该代码如何获取最新的YouTube视频在Laravel
$videoList = Youtube::listChannelVideos('UC9PWIZ20pnEXgT1fT69bX8A', 50);
但它显示我老首先我要到获取最新的第一我该怎么办 谢谢
该包中,我们可以SE这git仓库:
public function listChannelVideos($channelId, $maxResults = 10, $order = null, $part = ['id', 'snippet'], $pageInfo = false)
{
$params = array(
'type' => 'video',
'channelId' => $channelId,
'part' => implode(', ', $part),
'maxResults' => $maxResults,
);
if (!empty($order)) {
$params['order'] = $order;
}
return $this->searchAdvanced($params, $pageInfo);
}
这个功能似乎接受第三个参数 “命令”
因此,也许这项工作:
$videoList = Youtube::listChannelVideos('UC9PWIZ20pnEXgT1fT69bX8A', 50, "date");
我跑了你粘贴的片段,并且视频看起来并没有在一个订单 - 前几名是2016年,然后是2017年,然后是2016年。
您可以通过列表进行排序,获取最新的第一:
$videoList = Youtube::listChannelVideos('UC9PWIZ20pnEXgT1fT69bX8A', 50);
usort($videoList, function ($a, $b) {
return strtotime($a->snippet->publishedAt) < strtotime($b->snippet->publishedAt);
});
一旦列表进行排序,$videoList[0]
将包含最新的视频
我只是想这个包过,发现使用搜索方法可以遍历所有的视频,并在数据库中存储结果,同时捕捉发布日期其他属性。从那里你可以使用这些记录轻松按日期或标题等进行分类,并通过视频分页。这也节省了对你管API的多个请求。
其他人采取了这种方法?
我刚刚加入 $ videoList = youtube:listChannelVideos''UC9PWIZ20pnEXgT1fT69bX8A',50,“date”); 及其工作无需声明listChannelVideos功能 –