忽略 YouTube API V3 的播放列表
Ignore playlists for YouTube API V3
我有一个我编写的 C# 应用程序,它循环访问某些 youtuber 并从他们那里检索视频信息。我只关心视频本身。我最近 运行 遇到一个问题,有人创建或更新了一个播放列表,现在它出错了,因为它也把它拉进来了。有没有人知道在查询 YouTube 时跳过播放列表的方法?这就是我今天为特定 youtuber 提取视频列表的方式。
YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = YTubeAPIKey });
var searchListRequest = yt.Search.List("snippet");
searchListRequest.MaxResults = YTubeDownloadsPerUser;
searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date; // grab and order by newest to oldest
searchListRequest.ChannelId = youtubers;
根据 Search.list
API 端点的官方文档,如果您在调用请求参数的端点中包含适当的以下设置,那么您将仅获得对应于视频:
type
(string)
The type
parameter restricts a search query to only retrieve a particular type of resource. The value is a comma-separated list of resource types. The default value is video,channel,playlist
.
Acceptable values are:
channel
playlist
video
因此,只需将以下行添加到您的 API 代码中,即可为您提供仅与视频相关的资源:
searchListRequest.Type = "video";
另请注意,已设置请求参数 channelId
意味着 Search.list
将 return 有限数量的项目(下面的重点是我的):
channelId
(string)
The channelId
parameter indicates that the API response should only contain resources created by the channel.
Note: Search results are constrained to a maximum of 500 videos if your request specifies a value for the channelId
parameter and sets the type
parameter value to video
, but it does not also set one of the forContentOwner
, forDeveloper
, or forMine
filters.
我有一个我编写的 C# 应用程序,它循环访问某些 youtuber 并从他们那里检索视频信息。我只关心视频本身。我最近 运行 遇到一个问题,有人创建或更新了一个播放列表,现在它出错了,因为它也把它拉进来了。有没有人知道在查询 YouTube 时跳过播放列表的方法?这就是我今天为特定 youtuber 提取视频列表的方式。
YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = YTubeAPIKey });
var searchListRequest = yt.Search.List("snippet");
searchListRequest.MaxResults = YTubeDownloadsPerUser;
searchListRequest.Order = SearchResource.ListRequest.OrderEnum.Date; // grab and order by newest to oldest
searchListRequest.ChannelId = youtubers;
根据 Search.list
API 端点的官方文档,如果您在调用请求参数的端点中包含适当的以下设置,那么您将仅获得对应于视频:
type
(string)
Thetype
parameter restricts a search query to only retrieve a particular type of resource. The value is a comma-separated list of resource types. The default value isvideo,channel,playlist
.Acceptable values are:
channel
playlist
video
因此,只需将以下行添加到您的 API 代码中,即可为您提供仅与视频相关的资源:
searchListRequest.Type = "video";
另请注意,已设置请求参数 channelId
意味着 Search.list
将 return 有限数量的项目(下面的重点是我的):
channelId
(string)
ThechannelId
parameter indicates that the API response should only contain resources created by the channel.Note: Search results are constrained to a maximum of 500 videos if your request specifies a value for the
channelId
parameter and sets thetype
parameter value tovideo
, but it does not also set one of theforContentOwner
,forDeveloper
, orforMine
filters.