从播放列表中对 Youtube API 结果进行排序 [英] Sorting Youtube API result from playlist

查看:13
本文介绍了从播放列表中对 Youtube API 结果进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在一直在为 Youtube 的 API v3 苦苦挣扎,但我无法让它以我想要的方式工作.我的目标是将选定播放列表中的最新视频加载到我的网站中.问题是我只回复了最老的视频.

I have been struggling with Youtube's API v3 now and I can't get it work in the way I want. My goal is to load the latest videos from a selected playlist into my website. The problem is that I only the the oldest videos in my response.

要加载播放列表,我请求以下 API URI:https://www.googleapis.com/youtube/v3/playlistItems

To load the playlist I request following API URI: https://www.googleapis.com/youtube/v3/playlistItems

这是一个请求示例(只需单击执行):http://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.list?part=id%252Csnippet%252CcontentDetails%252Cstatus&playlistId=PLOU2XLYxmsIKGo-dgliIJQ4NZ6L3amp;bvh=1&

Here is an example of a request (just click execute): http://developers.google.com/apis-explorer/#p/youtube/v3/youtube.playlistItems.list?part=id%252Csnippet%252CcontentDetails%252Cstatus&playlistId=PLOU2XLYxmsIKGo-dgliIJQNZ6L3G8UV4b&_h=1&

如何对结果进行排序并首先获得最新的视频?我在文档中找不到任何东西,我一直在谷歌上搜索,但没有任何运气.如果您无法对结果进行排序,则此 API 毫无意义.唯一的方法是通过令牌不断加载下一页来加载所有视频,但这太疯狂了.

How can a sort the result and get the latest videos first? I can't find anything in the docs and I have been googling without any luck. There is no point with this API if you can't sort the result. The only way is to load all videos by keep loading the next page by token but that is just insane.

有什么想法吗?听起来像是一个基本问题,但我找不到解决方案...

Any idea? Sounds like a basic problem but I can't find a solution...

推荐答案

当前的 API 没有列出播放列表项目的排序选项,但如果您以编程方式插入项目,您可以指定 position 插入以使新视频显示在列表顶部时的值.

The current API doesn't have a sorting option for listing playlist items, but if you are inserting the items programmatically, you can specify the position value when inserting to make new videos appear at the top of the list.

如果是其他人在添加视频,则您必须获取所有页面.由于播放列表限制为 200 个项目,因此最多需要 4 个请求.不理想,但现在是唯一的选择.

If it's someone else that is adding the videos, than you'll have to get all pages. Since the playlists are limited to 200 items, this requires 4 requests at most. Not ideal, but it's the only option now.

这篇关于从播放列表中对 Youtube API 结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆