YouTube API - 使用播放列表查询获取所有视频的标签 [英] YouTube API - get tags for all videos with playlist query

查看:30
本文介绍了YouTube API - 使用播放列表查询获取所有视频的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查询 YouTube 频道以检索这样的播放列表元数据:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=5&playlistId={PLAYLIST_ID}&key={API_KEY}

此查询返回频道上所有视频的数组.该数组中的每个对象都包含提供每个视频元数据的各种字段,但这些字段都不包含与视频关联的标签.我可以使用这样的查询来获取该数据:

https://www.googleapis.com/youtube/v3/videos?key={API_KEY}&fields=items(snippet(title,description,tags))&part=snippet&id={VIDEO_ID}

问题在于,现在我需要为第一个查询中返回的每个视频发出单独的查询.

所以,我的问题是,有没有一种方法可以将这些标签作为第一个查询的初始 JSON 对象的一部分包含在内?我可以添加任何参数以请求将这些数据包含在该响应中吗?

感谢您的帮助!

解决方案

简短回答:否

PlaylistItems: list 文档没有显示从 playlistItems 端点获取视频标签的方法.唯一可用的部分是 idsnippetstatuscontentDetails,它们都不包含标签.

但是!

您不必对播放列表中的每个视频都提出请求!文档指出:

<块引用>

id 参数为正在检索的资源指定一个以逗号分隔的 YouTube 视频 ID 列表.在视频资源中,id 属性指定视频的 ID.(字符串)

这意味着您可以向 videos 端点提供多个以逗号分隔的视频 ID.

示例:

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

因此,您总共需要两次请求才能获取播放列表中所有视频的标签.*

*在实践中,您可能需要发出两个以上的请求.如果我没记错的话,YouTube 将每个请求退回的项目限制为 50 个.因此,如果播放列表包含超过 50 个视频,您将不得不使用 pageToken 参数 设置.

I'm querying YouTube channels to retrieve playlist metadata like this:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=5&playlistId={PLAYLIST_ID}&key={API_KEY}

This query returns an array of all of the videos on the channel. Each object in that array includes various fields that provide metadata on each video, but none of these fields include the tags associated with the video. I can get that data using a query like this:

https://www.googleapis.com/youtube/v3/videos?key={API_KEY}&fields=items(snippet(title,description,tags))&part=snippet&id={VIDEO_ID}

The problem with that is that now I need to issue a separate query for every single video that comes back in the first query.

So, my question is, is there a way that I can get these tags included as part of the initial JSON object from the first query? Can I add any parameters that will request this data be included with that response?

Thanks for any help!

解决方案

Short answer: No.

The PlaylistItems: list documentation does not show a way to get video tags from the playlistItems endpoint. The only parts available are id, snippet, status and contentDetails and neither of those contain tags.

However!

You do not have to make a request for each video in the playlist! The documentation states:

The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's ID. (string)

That means you can supply multiple, comma-separated video ids to the videos endpoint.

Example:

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

So in total, it will cost you two requests to get the tags of all videos in a playlist.*

*In practice, you might have to make more than two requests. If I remember correctly, YouTube limits the returned items to 50 per request. Thus, if the playlist contains more than 50 videos, you will have to make another request with the pageToken parameter set.

这篇关于YouTube API - 使用播放列表查询获取所有视频的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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