如何通过在 C# 中调用 YouTube API 来获取所有 Youtube 视频的持续时间
How to get Duration of all Youtube Videos by calling YouTube API in C#
我想在调用后获取列表中每个视频的时长youtubeService.Search.List("snippet");
以下是我的代码
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "API Key",
ApplicationName = this.GetType().ToString()
});
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.MaxResults = 30;
var searchListResponse = searchListRequest.Execute();
我看到视频的内容详情中有时长,但每个视频的内容详情都是空的。
检查 search.list you will see that it returns a list of search#resource
的文档后
{
"kind": "youtube#searchResult",
"etag": etag,
"id": {
"kind": string,
"videoId": string,
"channelId": string,
"playlistId": string
},
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"thumbnails": {
(key): {
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
},
"channelTitle": string,
"liveBroadcastContent": string
}
}
其中不包含有关视频持续时间的任何信息。此方法似乎没有返回您要查找的信息。
视频列表
只有 videos.list which contains a video.resource 会为您提供视频的时长
{
"kind": "youtube#video",
"etag": "U-t7IORpXf52WZSn6hBzfgm6WLo",
"id": "XOIZZEdfrfA",
"contentDetails": {
"duration": "PT8M51S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true,
"contentRating": {},
"projection": "rectangular"
}
我想在调用后获取列表中每个视频的时长youtubeService.Search.List("snippet");
以下是我的代码
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "API Key",
ApplicationName = this.GetType().ToString()
});
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.MaxResults = 30;
var searchListResponse = searchListRequest.Execute();
我看到视频的内容详情中有时长,但每个视频的内容详情都是空的。
检查 search.list you will see that it returns a list of search#resource
的文档后{
"kind": "youtube#searchResult",
"etag": etag,
"id": {
"kind": string,
"videoId": string,
"channelId": string,
"playlistId": string
},
"snippet": {
"publishedAt": datetime,
"channelId": string,
"title": string,
"description": string,
"thumbnails": {
(key): {
"url": string,
"width": unsigned integer,
"height": unsigned integer
}
},
"channelTitle": string,
"liveBroadcastContent": string
}
}
其中不包含有关视频持续时间的任何信息。此方法似乎没有返回您要查找的信息。
视频列表
只有 videos.list which contains a video.resource 会为您提供视频的时长
{
"kind": "youtube#video",
"etag": "U-t7IORpXf52WZSn6hBzfgm6WLo",
"id": "XOIZZEdfrfA",
"contentDetails": {
"duration": "PT8M51S",
"dimension": "2d",
"definition": "hd",
"caption": "false",
"licensedContent": true,
"contentRating": {},
"projection": "rectangular"
}