Youtube API 3 获取最新视频

Youtube API 3 获取最新视频

问题描述:

所以我试图从用户上传的 10 个最新视频中获取.

So I am trying to grab 10 latest videos from user uploads.

现在唯一的问题是 playlistitems 请求中唯一可见的日期是 publishedAt,即视频上传的日期- 不是公开日期,这会产生巨大的差异.

Now the only problem is that the only date visible in the playlistitems request is publishedAt which is the date when the video was uploaded - not the date of when it was made public, which makes a huge difference.

我注意到我可以通过视频请求获取正确的日期,但它似乎不是最好的地方.

I noticed that I can grab the correct date via the video request, but it just does not seem to be the best place to do it.

让我向你展示一个我正在处理的例子.

Let me show you an example of what I am dealing with.

我们来看看 Maroon5 频道.

Let's take Maroon5 channel.

forUserName:Maroon5VEVO

forUserName: Maroon5VEVO

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=Maroon5VEVO&key={YOUR_API_KEY}

GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=Maroon5VEVO&key={YOUR_API_KEY}

https://developers.google.com/youtube/v3/docs/channels/list#try-it

这是我们抓住的地方:

uploadsId: UUN1hnUccO4FD5WfM7ithXaw

uploadsId: UUN1hnUccO4FD5WfM7ithXaw

所以我们可以查询:

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUN1hnUccO4FD5WfM7ithXaw&maxResults=50&key={YOUR_API_KEY}

GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=UUN1hnUccO4FD5WfM7ithXaw&maxResults=50&key={YOUR_API_KEY}

https://developers.google.com/youtube/v3/docs/playlistItems/list#try-it

然后我们可以看一些视频.

and then we can have a look at some videos.

让我们获取最新的.对我来说就是这个:

Let's grab the latest one. For me it is this one:

"title": "Maroon 5 - 这个夏天会像一个人一样受伤......(明确)","videoId": "Wa64gOwuIyE"

"title": "Maroon 5 - This Summer's Gonna Hurt Like A ... (Explicit)", "videoId": "Wa64gOwuIyE"

最重要的是:

"publishedAt": "2015-06-01T17:41:58.000Z",

"publishedAt": "2015-06-01T17:41:58.000Z",

现在让我们通过运行以下查询来获取该视频的更多详细信息:

Now let's grab more details of this video, by running this query:

GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=Wa64gOwuIyE&key={YOUR_API_KEY}

GET https://www.googleapis.com/youtube/v3/videos?part=snippet&id=Wa64gOwuIyE&key={YOUR_API_KEY}

https://developers.google.com/youtube/v3/docs/videos/list#try-it

在这里,我们获得了更详细的视图,其中包含...不同的日期!

Here we get more detailed view with a date that is ... different !

"publishedAt": "2015-06-01T20:00:01.000Z",

"publishedAt": "2015-06-01T20:00:01.000Z",

这意味着播放列表中的publishedAt 日期实际上是上传的日期,而不是视频公开的日期.

That means that the publishedAt date in playlists is actually the date of the upload - not when the video was made public.

在我们的 10 个最新项目列表中,我们想要最新发布的视频,而不是最新上传的视频.

In our list of 10 latest items we want the LATEST published videos , and not latest uploaded vids.

如果你知道如何处理它,请分享.

If you know a way how to approach it , please share.

这是我现在的片段(使用错误的发布日期)

Here is my snippet for now (working with a wrong publishedAt date)

 $.get(
        "https://www.googleapis.com/youtube/v3/playlistItems",{
        part : 'snippet',
        maxResults : 10,
        playlistId : UPLOADS_PID,
        key: YOUR_API_KEY},
        function(data) {

            $.each( data.items, function(i, item ) {                

                (...)

            });
        }
    );

我相信你可以使用/search 端点.如果您想从用户上传的视频中获取 10 个最新视频,您可以使用频道 ID 而不是播放列表 ID.

I believe you can use /search endpoint. As you want to grab 10 latest videos from user uploads, you can use channel id instead of playlist id.

请求:

GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&maxResults=10&order=date&type=video&key={YOUR_API_KEY}