YouTube 播放列表项 API 已发布在字段说明中 [英] YouTube Playlist Item API publishedAt field clarification
问题描述
我已经测试了 YouTube 的 PlaylistItems.list
用于获取频道默认播放列表的 API.
在响应负载中,发布于 2020-10-14T20:22:24Z 的视频位于第一个对象中,然后是发布于 2020-10-21T17 的下一个视频:54:05Z -- 在第二个物体中.
在这个答案中提到:
<块引用>从播放列表查询返回的publishedAt 是日期视频已添加到播放列表中,而不是视频的日期在 YouTube 上发布
我的情况可能是什么原因?
是否有为此 API 维护的特定排序顺序?
您看到示例排序的原因(尽管您没有提及您的播放列表 ID,以便其他人验证您的声明)有两个原因.
>
1.视频的发布时间很可能与其上传时间不同
第一件事如下:根据视频资源的官方文档 publishedAt
属性(下面的重点是我的):
snippet.publishedAt
(日期时间)
发布视频的日期和时间.请注意,此时间可能与上传视频的时间不同.例如,如果视频作为私人视频上传,然后在稍后公开,则此属性将指定时间该视频已公开.
有几种特殊情况:
- 如果视频作为私人视频上传并且视频元数据由频道所有者检索,则属性值指定视频上传的日期和时间.
- 如果视频是作为不公开视频上传的,则该属性值还会指定视频的上传日期和时间.在这种情况下,任何知道视频唯一视频 ID 的人都可以检索视频元数据.
该值以 ISO 8601 格式指定.
因此,在某些情况下,很可能给定的视频具有不同的上传时间和发布时间.
此外,PlaylistItems 资源的官方文档如下所述写两个相关的属性:
<块引用>snippet.publishedAt
(日期时间)
项目添加到播放列表的日期和时间.该值以 ISO 8601 格式指定.
<块引用>
contentDetails.videoPublishedAt
(日期时间)
视频发布到 YouTube 的日期和时间.该值以 ISO 8601 格式指定.
根据 snippet.publishedAt
的规范,如果播放列表是给定频道的上传播放列表(即 ID 格式为 UU...
; 注意,通常一个频道ID和它对应的上传播放列表ID通过s/^UC([0-9a-zA-Z_-]{22})$/UU\1/
,虽然没有正式记录),snippet.publishedAt
的值是该视频的上传日期.
第二个规范,表示contentDetails.videoPublishedAt
的值是对应视频资源的snippet.publishedAt
,即该视频的发布时间.>
2.对于频道的上传播放列表,PlaylistItems.list
API 端点返回的项目(必须)按 contentDetails.videoPublishedAt<按时间倒序排序/code>
确实,排序条件似乎是正确的.此功能未正式记录,但根据我的经验,上述声明适用于从 PlaylistItems.list
端点获得的每个结果集.
我可以在这里提出以下论点,证明在调用 PlaylistItems.list
端点时产生的项目必须由 contentDetails.videoPublishedAt<按时间倒序排列(最新的在前)/代码>:
这个论点是实用的:如果 PlaylistItems.list
的结果集没有按照前面提到的那样排序,那么这个端点就没有用了.
之所以如此,是因为在这种情况下,要获取最近发布的视频必须在本地获取所有上传的项目(其中 设计限制为 20000),然后扫描该结果集以获得最新的结果.被迫获取所有上传的项目只是为了获得最新的项目在实用上是无稽之谈.如果给定频道的上传次数超过 20000 的限制,则最近的视频可能会超出此边界;因此,对于此类频道,根本无法从 API 中获取最近发布的视频.
因此,矛盾的是,结果集必须按contentDetails.videoPublishedAt
按时间倒序排序.
I have tested YouTube's PlaylistItems.list
API to fetch a channel's default playlist.
In the response payload, a video -- that was published on 2020-10-14T20:22:24Z -- is in the first object, and then the next video -- that was published on 2020-10-21T17:54:05Z -- is in the second object.
In this answer it is mentioned that:
The publishedAt getting returned from a Playlist query is the date the video was added to the playlist, rather than the date the video was published on YouTube
What might be the reason for my case?
Is there any specific sorting order maintained for this API?
The reason you see the ordering you've exemplified (though you did not mentioned your playlist ID such that others to verify your claim) is two fold.
1. A video's publication time may well be different than its upload time
First thing is the following: according to the official docs of the Video resource's publishedAt
property (the emphasis below is mine):
snippet.publishedAt
(datetime)The date and time that the video was published. Note that this time might be different than the time that the video was uploaded. For example, if a video is uploaded as a private video and then made public at a later time, this property will specify the time that the video was made public.
There are a couple of special cases:
- If a video is uploaded as a private video and the video metadata is retrieved by the channel owner, then the property value specifies the date and time that the video was uploaded.
- If a video is uploaded as an unlisted video, the property value also specifies the date and time that the video was uploaded. In this case, anyone who knows the video's unique video ID can retrieve the video metadata.
The value is specified in ISO 8601 format.
Therefore, in cases, it may very well be that a given video has different upload time and time of publication.
Furthermore, the official docs of PlaylistItems resource says the following w.r.t. two related properties:
snippet.publishedAt
(datetime)The date and time that the item was added to the playlist. The value is specified in ISO 8601 format.
contentDetails.videoPublishedAt
(datetime)The date and time that the video was published to YouTube. The value is specified in ISO 8601 format.
From the spec of snippet.publishedAt
, it follows that, in the case of a playlist being the uploads playlist of a given channel (that is a playlist of which ID is of form UU...
; note that, usually, a channel ID and its corresponding uploads playlist ID are related by s/^UC([0-9a-zA-Z_-]{22})$/UU\1/
, though not documented officially), the value of snippet.publishedAt
is the upload date of that video.
The second spec, indicates that the value of contentDetails.videoPublishedAt
is that of the corresponding Video resource's snippet.publishedAt
, the time of publication of that video.
2. For the uploads playlist of a channel, the items returned by PlaylistItems.list
API endpoint are (have to be) ordered in reverse chronological order by contentDetails.videoPublishedAt
Indeed, the ordering condition seems to be true. This feature is not documented officially, but, in my experience, the statement above holds true for every result set obtained from PlaylistItems.list
endpoint.
I could make here the following argument justifying the necessity that the items resulted upon the invocation of PlaylistItems.list
endpoint be ordered in reverse chronological order (newest first) by contentDetails.videoPublishedAt
:
This argument is of a pragmatic kind: if the result set of PlaylistItems.list
is not ordered as mentioned, then this endpoint becomes useless.
This is so, since, in this case, for one to obtain the most recently published video would have to fetch locally all the uploaded items (the number of which is limited by design to 20000), for to then scan that result set for the most recent one. Being compelled to fetch all uploaded items only for to obtain the newest one is pragmatically a nonsense. If the number of uploads of a given channel exceeds the limit of 20000, then the most recent video could possibly fall outside this boundary; thus, for such kind of channels, the most recently published video could not be obtained from the API at all.
Therefore, by way of contradiction, the result set has to be ordered in reverse chronological order by contentDetails.videoPublishedAt
.
这篇关于YouTube 播放列表项 API 已发布在字段说明中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!